android – Split layout into 2 columns

Question:

I have my splash screen code that needs to be split into two equal parts. How do I split a linear layout into two equal-sized columns?

Answer:

You can use weight:

layout_weight= "1"

If the elements have the same weight, they will be the same size.

Example:

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerHorizontal="true">

    <EditText
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

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

The documentation follows.

Greetings

Scroll to Top