How to center the entire layout

Asked

Viewed 5,357 times

3

I have the following layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <Button>

    <TableLayout>android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:layout_gravity="center_horizontal">

        (Aqui tem algumas <TableRows>)

    </TableLayout>

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

        <Button>

    </LinearLayout>
</LinearLayout>

You have to make sure that everything is centered vertically, from the first button to the last, keeping organized as it is. I tried putting android:layout_centerVertical="true" but it doesn’t work. What should I do?

  • tries using android:layout_centerInParent="true"on the first level, I, after suffering a lot with the positioning of components on the screen, saw that the best way is to nesting linearlayouts and inside them the structures I need

  • did not work for me, I put in the first level <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"&#xA; android:layout_width="match_parent"&#xA; android:layout_height="match_parent"&#xA; android:orientation="vertical"&#xA; android:layout_centerInParent="true">

  • put your layout file in the answer so you can see what can be done

  • Thank you very much Armando, but I did it with a simple android:gravity:"center", how had I not done it before? I don’t know. kk

1 answer

1

Try to use the parameter android:gravity="center_vertical" in the parent Linearlayout. If you want to adjust each View separately, you can use the parameter android:layout_gravity in the desired View.

Browser other questions tagged

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