Problems with XML in android studio

1

Hello, I am learning to use android studio and I had a problem. The thing is I want to recreate the screen design I did next and had planned to mount it in two linearlayout, which would be the row marked with a 1 and 2, then put different elements; both are in turn within a relativeLayout.

The problem I have is when it comes to position and size. The dila of the first LinearLayout which is marked in the image with a (2) I put android:layout_height="60dp" and the (1) would have to adjust the height to (2). I have already tried to indicate with layout_below .

    
asked by Omega96 17.05.2018 в 20:45
source

1 answer

0

I would not recommend that you use a fixed value for the size of your Layouts, since maybe in one phone it looks good with that value that you added but in others it does not. The right thing to do would be to create a parent LinearLayout that contains your other two LinearLayouts. You can sort everything using android:weightSum I'll show you an example:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="5">

    <!--LinearLyout 1-->

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent" 
        android:layout_weight="4">
    </LinearLayout>

    <!--LinearLyout 2-->

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1">
    </LinearLayout>

</LinearLayout>

This will make your Layout (1) with android:layout_weight="4" occupy the largest space on the screen and the Layout (2) android:layout_weight="1" will occupy only a small part as required by the design you showed above. It also works for any resolution. I leave you a Link with an example that does it with 3 Buttons . On the web there are many people with this type of doubt regarding the Layouts, you can find more examples or explanations if you did not get it completely clear.

    
answered by 17.05.2018 в 22:58