Problem with same Android Studio screens

1

I have a problem, two cell phones of the same screen size, only one has the button bar included in the screen, and it looks to the side.

This is the screen where it looks bad if you can see this as a side run

And this is the screen where it looks good

Layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/content_primera"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="1"
    tools:context="srf.lec.noctambuloss.Primera"
    android:background="@drawable/fondoo">

    <Space
        android:layout_width="match_parent"
        android:layout_height="40dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/titulo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/titulo"
            android:text="Noctambulos"
            android:textSize="30dp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <Space
            android:layout_width="80dp"
            android:layout_height="50dp" />

    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal"
        android:weightSum="1">

        <ImageButton
            android:id="@+id/bolichesybaresbutton"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_marginBottom="74dp"
            android:layout_marginLeft="47dp"
            android:background="@drawable/baresyboli" />

        <Space
            android:layout_width="70dp"

            android:layout_height="44dp" />

        <ImageButton
            android:id="@+id/mapabutton"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="74dp"
            android:layout_marginRight="15dp"
            android:background="@drawable/mapaa" />

    </LinearLayout>

    <Space
        android:layout_width="match_parent"
        android:layout_height="50dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal">

        <ImageButton
            android:id="@+id/buttonsugerencia"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_marginBottom="74dp"
            android:layout_marginLeft="47dp"
            android:background="@drawable/sugerencias" />

        <Space
            android:layout_width="65dp"
            android:layout_height="39dp" />

        <ImageButton
            android:id="@+id/buttonprevia"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="74dp"
            android:layout_marginRight="15dp"
            android:background="@drawable/previex" />
    </LinearLayout>


    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <Space
            android:layout_width="80dp"
            android:layout_height="50dp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Space
            android:layout_width="125dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <ImageButton
            android:id="@+id/buttoncontacto"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_marginBottom="25dp"
            android:layout_weight="1"

            android:background="@drawable/contactanos" />
    </LinearLayout>

</LinearLayout>

What I want to do is make it look the same for all screens.

    
asked by Emiliano Rigobello 05.04.2017 в 18:47
source

1 answer

0

It looks aside because in reality your layout contains fixed values, for example in the second block of elements you have android:layout_marginLeft="47dp" and then android:layout_marginRight="15dp" , even you are using weights unnecessarily, with this you can not center the elements in all possible widths and densities of devices!.

In this case, delete unnecessary margins or padding add to your button container android:gravity="center" , for example:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:orientation="horizontal"
    android:gravity="center">

It is important to eliminate the fixed margins, this so that you have a uniform distribution regardless of the size or density of the screen.

I made a change to your layout so you can see the necessary changes, it's even easier to avoid adding unnecessary properties:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/content_primera"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="1"
    tools:context="srf.lec.noctambuloss.Primera"
    android:background="@drawable/fondoo">

    <Space
        android:layout_width="match_parent"
        android:layout_height="40dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/titulo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/titulo"
            android:text="Noctambulos"
            android:textSize="30dp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <Space
            android:layout_width="match_parent"
            android:layout_height="50dp" />

    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal"
        android:gravity="center">

        <ImageButton
            android:id="@+id/bolichesybaresbutton"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:background="@drawable/baresyboli" />

        <Space
            android:layout_width="70dp"
            android:layout_height="44dp" />

        <ImageButton
            android:id="@+id/mapabutton"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:background="@drawable/mapaa" />

    </LinearLayout>

    <Space
        android:layout_width="match_parent"
        android:layout_height="50dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal"
        android:gravity="center">

        <ImageButton
            android:id="@+id/buttonsugerencia"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:background="@drawable/sugerencias" />

        <Space
            android:layout_width="65dp"
            android:layout_height="39dp" />

       <ImageButton
            android:id="@+id/buttonprevia"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:background="@drawable/previex" />
    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <Space
            android:layout_width="match_parent"
            android:layout_height="50dp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center">

        <ImageButton
            android:id="@+id/buttoncontacto"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:background="@drawable/contactanos" />
    </LinearLayout>

</LinearLayout>
    
answered by 21.07.2017 в 18:06