如何在android中创建两个固定大小的视图和一个跨越它们的视图?

时间:2013-07-29 21:24:36

标签: java android xml android-layout layout

我想创建一个屏幕

有两个固定大小的区域:一个对齐左,一个对齐

在他们之间还有另一个跨越该地区所有其他区域的区域?

如果我使用属性fill_parent创建中间视图,它将捕获第3个孩子的所有区域。

layout_weight=0.Xlayout_width=20dp时的有效属性是什么。?

==

我有一个orientation= horizontal的linearLayout。

它有一个layout_weight=0.Xlayout_width=20dp的孩子。

什么是有效财产?

2 个答案:

答案 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