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>

更多相关文章

  1. 按下子活动后退按钮后,Android主要活动的元素不响应
  2. JSP页面中有一个按钮 点击之后执行JAVA文件
  3. 不幸的是,在声明按钮时,模拟器中出现了错误
  4. 基于内容估计文本宽度的算法
  5. 单击按钮后更改Frame的内容窗格
  6. jQuery(JavaScript)获取文字(字符串)宽度(显示长度)
  7. 在Java中选择showMessageDialog框右上角的x按钮退出系统?

随机推荐

  1. Mac 10.12 快速下载 Android 源码
  2. Android关于SD卡的读写操作及固定图片大
  3. Android(安卓)DLNA
  4. 解决 Android模拟器无法上网问题——Host
  5. android UDID获取:android 设备SN的获取
  6. android中自定义播放器的实现
  7. 访问本地服务器
  8. Android 中的布局方式之线性布局
  9. 极光推送使用实例(三) Android客户端
  10. Android内存泄漏监测(MAT)及解决办法