安卓,如何让两个按钮相邻,宽度相同
16lz
2021-01-22
Im trying to place two buttons on the xml next to each other and I want them both to be the same size(half from the width of the screen) - this is my xml:
我试着把两个按钮放在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>
Everything works well, but when im changing the text in java, the width is changing, how can I make them the same size?
一切都运行得很好,但是当我在java中修改文本时,宽度在变化,我如何使它们保持相同的大小?
Thanks
谢谢
1 个解决方案
#1
4
When you set the weight of the view then you shouldn't use any values for the width / height. Set the width of the buttons to 0dp. You also don't need android:weightSum="2"
设置视图的权重时,不应该对宽度/高度使用任何值。将按钮的宽度设置为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>
更多相关文章
- 按下子活动后退按钮后,Android主要活动的元素不响应
- JSP页面中有一个按钮 点击之后执行JAVA文件
- 不幸的是,在声明按钮时,模拟器中出现了错误
- 基于内容估计文本宽度的算法
- 单击按钮后更改Frame的内容窗格
- jQuery(JavaScript)获取文字(字符串)宽度(显示长度)
- 在Java中选择showMessageDialog框右上角的x按钮退出系统?