Difficulty hitting the buttons in the layout

Asked

Viewed 30 times

0

I can’t get the Buttons on the layout like I want. I wanted to leave one button at the center and the others at the bottom (bottom) below what is at the center. Only they don’t get right and I can’t get it right.

<LinearLayout
    android:orientation="vertical"
    android:layout_height="match_parent"
    android:weightSum="1"
    android:layout_width="match_parent"
    android:gravity="center">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="523dp"
        android:gravity="bottom|center">

        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/button10"
            android:layout_weight="1"
            android:background="@drawable/hohoho" />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="99dp"
        android:gravity="top">

        <Button
            android:text="Button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button9"
            android:layout_weight="1" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button8"
            android:layout_weight="1" />
    </LinearLayout>
</LinearLayout>

  • You can provide a wireframe or simple image of the result you expect?

  • yes I can, use a simple image

1 answer

0


Its "bigger" layout has to have a weightSum of 2, because inside it has 2 other layouts. These two smaller layouts must be Relativelayout with the layout_weight attribute of 1 each layout, to total the sum of value 2. In this way, the screen will be divided perfectly.
Then, inside the top layout, Oce puts the button and places the gravity of the layout to throw everything down. In the bottom layout, Voce puts the buttons and puts gravity up.
This way, all buttons will be perfectly centered regardless of screen size.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.