是否可以将小部件宽度分配为可用屏幕宽度的一半,并使用声明性 xml 来实现?
如果您的小部件是一个按钮:
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="2"
android:orientation="horizontal">
<Button android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="somebutton"/>
<TextView android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
我假设您希望您的小部件占据一半,而另一个小部件占据另一半。技巧是使用 LinearLayout,设置layout_width="fill_parent"
在两个小部件上,并设置layout_weight
两个小部件上的值也相同。如果有两个具有相同权重的小部件,LinearLayout 将分割两个小部件之间的宽度。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)