我试图将两个按钮彼此相邻放置在xml上,我希望它们的大小都相同(距离屏幕宽度的一半)-这是我的xml:
<LinearLayout
android:layout_width="fill_parent"
android:orientation="horizontal"
android:id="@+id/linearLayout2"
android:layout_height="fill_parent"
android:gravity="bottom"
android:weightSum="2">
<Button
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/bAddDelete"
/>
<Button
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/bMainMenu"
/>
</LinearLayout>
一切正常,但是当我在java中更改文本时,宽度也在变化,我如何使它们具有相同的大小?
谢谢
设置视图的权重时,不应为宽度/高度使用任何值。将按钮的宽度设置为0dp。您也不需要android:weightSum =“ 2”
<LinearLayout
android:layout_width="fill_parent"
android:orientation="horizontal"
android:id="@+id/linearLayout2"
android:layout_height="fill_parent"
android:gravity="bottom">
<Button
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/bAddDelete"
/>
<Button
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/bMainMenu"
/>
</LinearLayout>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句