[英]how to create two fixed size views and one view spanned between them in android?
I want to create a screen 我想创建一个屏幕
with two fixed size areas: one aligned to left, one to the right 具有两个固定大小的区域:一个区域向左对齐,一个区域向右对齐
and in between them another area which spans all the rest of the area? 在它们之间的另一个区域跨越了所有其他区域?
If I make the middle view with property fill_parent
it will catch all the area to the 3rd child. 如果我使用属性fill_parent
进行中间视图,它将捕获到第三个孩子的所有区域。
what will be the effective property when layout_weight=0.X
and layout_width=20dp
.? 当layout_weight=0.X
和layout_width=20dp
时,有效属性是什么?
====== ======
I have a linearLayout with orientation= horizontal
. 我有一个direction orientation= horizontal
的linearLayout。
It has a child with layout_weight=0.X
and also layout_width=20dp
. 它有一个layout_weight=0.X
的孩子,还有layout_width=20dp
。
What will be the effective property? 什么是有效财产?
If you have a horizontal LinearLayout
with the first child with a fixed width (eg layout_width="20dp"
), the second child with a non-zero weight (eg layout_weight="1"
) and the third with a fixed width (eg layout_width="20dp"
), then you should get the first aligned to the left, the third aligned to the right and the third filling the area between them. 如果您具有水平LinearLayout
,并且第一个子级具有固定的宽度(例如, layout_width="20dp"
),第二个子级具有非零的权重(例如, layout_weight="1"
),而第三个子级具有固定的宽度(例如, layout_width="20dp"
),那么您应该使第一个与左侧对齐,第三个与右侧对齐,第三个填充它们之间的区域。
It's also possible to do this with a RelativeLayout
, but I'll leave that as the above solution should work just fine. 也可以使用RelativeLayout
做到这一点,但我将保留上述内容,因为上述解决方案应该可以正常工作。
It will be something like this: 将会是这样的:
<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>
You should use android:layout_weight
. 您应该使用android:layout_weight
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.