简体   繁体   中英

Android: Relative layout for Row.xml

I tried many times to draw a relative layout like shown in the image below. But not succeed. 在此处输入图片说明

I design the image with paint to explain a bit better what i mean. Any suggestions?

Try this (it's the layout I proposed first in my comment):

<LinearLayout
    xmlns
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal"
        >
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="20"
        />
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="40"
        />
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="20"
        />
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="20"
        />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal"
        >
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
        />
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
        />
    </LinearLayout>
</LinearLayout>

To make it more usable (ie: to assign contents dynamically), give these TextViews some ids ( android:id="@+id/txtSomething" ).

Obvoiusly, you can use any other control instead of TextViews: Buttons, ImageViews, in any combination.

Try the following idea:

Root - linear layout (vertical) with 2 childs

first child - linear layout (horizontal) with weights according to your UI second child - linear layout (horizontal) with weight 1 for its 2 childs.

您也可以使用TableLayout ...但是它很复杂。具有2行的表布局,其中第一行有4个子项,第二行有2个子项...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM