【问题标题】:My radio buttons are going out of screen我的单选按钮正在离开屏幕
【发布时间】:2012-01-06 10:17:51
【问题描述】:

我在相对布局中使用单选按钮,这是我的代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent" >

<FrameLayout android:id="@+id/frameLayout"  android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:layout_alignParentTop="true"
    android:layout_above="@+id/radioButtonGroupLayout">
<!-- Put fragments dynamically -->

</FrameLayout>


<RadioGroup android:id ="@+id/radioButtonGroupLayout" android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" android:layout_alignParentBottom="true">

    <RadioButton android:id="@+id/RadioButton1" 
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:button="@drawable/ip4_menu_but_1_selector" android:background="@drawable/ip4_menu_background_short72"/>
    <RadioButton android:id="@+id/RadioButton2" 
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:button="@drawable/ip4_menu_but_2_selector" android:background="@drawable/ip4_menu_background_short72"/>
    <RadioButton android:id="@+id/RadioButton3" 
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:button="@drawable/ip4_menu_but_3_selector" android:background="@drawable/ip4_menu_background_short72"/>
    <RadioButton android:id="@+id/RadioButton4" 
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:button="@drawable/ip4_menu_but_4_selector" android:background="@drawable/ip4_menu_background_short72"/>
    <RadioButton android:id="@+id/RadioButton5" 
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:button="@drawable/ip4_menu_but_5_selector" android:background="@drawable/ip4_menu_background_short72"/>
</RadioGroup>
</RelativeLayout>

最后一个单选按钮不在屏幕上。我只能看到前 4 个单选按钮和最后一个单选按钮。我的代码有什么问题?

【问题讨论】:

  • 你能给我们看个屏幕截图吗?这是可能的,因为您将 wrap_content 用于单选按钮,它们显示的尺寸与您用于按钮和背景的可绘制对象一样大。我建议将这些高度和宽度更改为固定 dp,这样它可以更好地缩放到更大/更小的屏幕。
  • 谢谢你,迈克尔,我改变了图像大小,还添加了 layout_weight = "1" 到所有单选按钮以分配剩余空间......并且它的工作......谢谢你的所有帮助
  • 尝试将所有内容嵌套在滚动视图中。

标签: android radio-button android-relativelayout radio-group


【解决方案1】:

这是可能的,因为您使用 wrap_content 作为单选按钮,它们显示的尺寸与您用于按钮和背景的可绘制对象一样大。我建议将这些高度和宽度更改为固定 dp,这样它可以更好地缩放到更大/更小的屏幕。

添加此评论作为答案,以便可以关闭问题。

【讨论】:

    【解决方案2】:

    对每个单选按钮使用 android:layout_weight="1"。它会在屏幕上显示所有 5 个任意大小的按钮。

     <RadioButton
            android:id="@+id/RadioButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    

    请对所有单选按钮执行相同操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多