【问题标题】:Why is my RadioGroup so large yet devoid of contents/RadioButtons?为什么我的 RadioGroup 这么大却没有内容/RadioButtons?
【发布时间】:2014-06-04 19:08:15
【问题描述】:

这是我的 Android 布局文件中的 XML 部分,它应该生成一个 RadioGroup,其中包含三个 RadioButtons:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <RadioButton
            android:id="@+id/radbtnAlways"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:checked="true"
            android:text="@string/radiobutton_Always" />

        <RadioButton
            android:id="@+id/radbtnNever"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/radiobutton_Never" />

        <RadioButton
            android:id="@+id/radbtnCost_Change"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/radiobutton_Cost_Change" />

    </RadioGroup>
</LinearLayout>

但是,我所看到的这些小部件应该在的位置只是科罗拉多州的蓝色轮廓 - 它太大了,并且没有显示单选按钮:

为什么我的 RadioGroup 这么大,为什么 RadioButton 会模仿 George Jones?

更新

在回答 CommonsWare 时,它​​在模拟器中看起来是这样的(几乎相同):

【问题讨论】:

  • 如果您的屏幕截图来自一些图形预览,请在设备或模拟器上尝试。如果您的屏幕截图来自设备或模拟器,请使用 Hierarchy View(模拟器)或 uiautomatorviewer(设备)来更好地了解正在发生的事情。话虽如此,使用android:layout_weight 控制高度与您的高度为wrap_content 是不一致的。
  • 它在设计时来自 Droidio。从 RadioButtons 中删除 layout_weight 没有任何区别。
  • 能否请您发布整个 xml 代码?

标签: android android-layout android-linearlayout android-radiogroup android-radiobutton


【解决方案1】:

从所有 RadioButtons 中移除这两个属性:

android:layout_width="0dip"
android:layout_weight="1"

所以现在看起来更好了:

【讨论】:

猜你喜欢
  • 2017-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-19
  • 2014-09-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多