如果您的小部件是一个按钮:
<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将在这两个小部件之间分割宽度.