随着各种大屏幕的安卓机器的出现,适配问题的重要性越来越明显,这里我给大家介绍一下如何使得两个按钮各占屏幕的一半,同理也可以让3个、4个甚至更多的按钮或者其他控件来实现平均占有屏幕的宽度。
实现的代码如下:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="45dp"
android:orientation="horizontal"
android:weightSum="2" >
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#666"/>
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#888"/>
</LinearLayout>
实现的效果就是两个按钮,各占屏幕一半的宽度。