安卓:2相对布局分为两半屏幕布局、屏幕

2023-09-12 11:23:36 作者:某个心跳

我试过很多次吸取2相对布局在水平方向排列,并在半屏分。

I tried many times to draw 2 Relative layout aligned horizontally and divided in half screen.

我设计用油漆的形象来解释会好一点我的意思。

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

任何建议?

推荐答案

您可以把这些2 RelativeLayouts与水平方向一的LinearLayout内,然后使用的 重量为RelativeLayouts。这要分的LinearLayout在2等份。

You can put these 2 RelativeLayouts inside a LinearLayout with horizontal orientation, then use the weight for both RelativeLayouts. This will divide the LinearLayout in 2 equal parts.

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:baselineAligned="false">
    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1">
   </RelativeLayout>
   <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1">
   </RelativeLayout>
</LinearLayout>