我想知道如何获得这个结果:
http://img718.imageshack.us/img718/6173/screenshot20100411at126.png
这是我尝试过的:
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#CCCCCC"
android:orientation="horizontal"
android:layout_weight="0">
<Button android:id="@+id/btn_cancel"
android:text="@string/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5px"
android:gravity="left"
/>
<Button android:id="@+id/btn_save"
android:text="@string/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5px"
android:layout_toRightOf="@id/btn_cancel"
android:gravity="right"/>
</RelativeLayout>
我尝试使用layout_width属性并将它们设置为填充 parent 双方,但没有成功,如果有人有想法......谢谢!
最佳答案
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:background="#CCCCCC"
android:orientation="horizontal">
<Button android:id="@+id/btn_cancel"
android:text="@string/cancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"
android:layout_weight="1"/>
<Button android:id="@+id/btn_save"
android:text="@string/save"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
在 LinearLayout 中让两个小部件占用相同空间量的技巧是在它们两个上设置 layout_width="fill_parent"
,然后设置 layout_weight="1 “
对他们两个也是如此。将两者设置为 fill_parent 和相同的layout_weight 将告诉 LinearLayout 在两者之间分割所有可用空间。
此外,使用dip
,而不是px
。 dip
与屏幕尺寸无关,并且在不同尺寸的屏幕上看起来会更好。
关于android - 这个布局该怎么做呢? (图片上的链接),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2620246/