我想创建一个屏幕
有两个固定大小的区域:一个对齐左,一个对齐
在他们之间还有另一个跨越该地区所有其他区域的区域?
如果我使用属性fill_parent
创建中间视图,它将捕获第3个孩子的所有区域。
layout_weight=0.X
和layout_width=20dp
时的有效属性是什么。?
==
我有一个orientation= horizontal
的linearLayout。
它有一个layout_weight=0.X
和layout_width=20dp
的孩子。
什么是有效财产?
答案 0 :(得分:1)
如果您的第一个孩子的水平LinearLayout
具有固定宽度(例如layout_width="20dp"
),则第二个孩子的权重非零(例如layout_weight="1"
),第三个孩子如果有一个固定的宽度(例如layout_width="20dp"
),那么你应该让第一个对齐到左边,第三个对齐到右边,第三个填充它们之间的区域。
也可以使用RelativeLayout
执行此操作,但我会留下,因为上述解决方案应该可以正常工作。
答案 1 :(得分:0)
会是这样的:
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<View android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<View android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<View android:id="@+id/view3"
android:layout_width="20dp"
android:layout_height="wrap_content"
android:layout_weight="0"/>
</LinearLayout>
您应该使用android:layout_weight
。