我需要设置我的视图的宽度作为在屏幕的宽度的50%,然后水平居中同时潜在地具有可出现连接到左或右侧的1个或多个按钮这一观点屏幕。的Android百分比宽度布局
我使用的相对布局,这样我可以放置一个线性布局与重量来获得,同时将在连接到RL的左或右边缘LL的顶部上的任何按钮居中我的50%。但是这种布局缺少蓝色的中间栏。如果我将中间视图layout_weight设置为1,则会得到3个相同大小的条。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp">
<LinearLayout
android:id="@+id/stupid_android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<View
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#FF0000"
android:layout_weight="1" />
<View
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#0000FF"
android:layout_weight="2" />
<View
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#00FF00"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
这是怎么了'layout_weight'作品。 'layout_weight'告诉你如何** **剩余在父空间'View'应该由孩子'View'的devided。在你的情况首先'View'有'安卓layout_width'设置为'fill_parent'所以没有任何实际剩余空间。我不知道为什么最后一个视图仍然可见,因为我只能看到第一个视图。 – 2013-03-04 15:16:11