【问题标题】:Android Radio Button Text Is MisplacedAndroid单选按钮文本放错了位置
【发布时间】:2013-09-27 15:06:49
【问题描述】:

我创建了一个包含一些RadioGroups 和RadioButtons 的布局。 RadioGroups 的父布局是 RelativeLayout,如果可能的话,我想留在 RelativeLayout

在大多数设备中,RadioButton 的圆圈位于文本的左侧,必须如此,如下所示:

但在某些设备中(我注意到设置为希伯来语的三星设备存在问题),圆圈实际上是文本上,如下所示:

这是我的代码(我删除了布局中不相关的其他项目):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/some_color1"
android:gravity="left" >

<RadioGroup
    android:id="@+id/group1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@id/key1"
    android:layout_below="@id/key5"
    android:layout_marginTop="@dimen/size4"
    android:orientation="horizontal" >

    <RadioButton
        android:id="@+id/u_hour"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:gravity="left|center_vertical"
        android:text="@string/hour"
        android:textSize="@dimen/size8" />

    <RadioButton
        android:id="@+id/u_day"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="left|center_vertical"
        android:text="@string/day"
        android:textSize="@dimen/size8" />

    <RadioButton
        android:id="@+id/u_week"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="left|center_vertical"
        android:text="@string/week"
        android:textSize="@dimen/size8" />
</RadioGroup>

我没有发现对这个问题有任何帮助,请有人告诉我解决它的方法吗?

【问题讨论】:

  • 您想发布您的代码还是 Sherlock 之家会修复它
  • 好的,我添加了我的布局。

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


【解决方案1】:

问题是您使用的是RelativeLayout。尝试改用LinearLayout。这是用于水平或垂直排列对象的一种。检查指南或示例;那里有很多。

我会这样尝试:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="?android:listPreferredItemHeightLarge"
    android:orientation="horizontal"
    android:showDividers="middle"
    android:divider="?android:dividerVertical"
    android:dividerPadding="8dp"
    android:gravity="center"
    android:background="#FFFFFF"
    android:layout_marginTop="8dp">



<RadioButton
    android:id="@+id/u_hour"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:checked="true"
    android:gravity="left|center_vertical"
    android:text="@string/hour"
    android:textSize="@dimen/size8" />

<RadioButton
    android:id="@+id/u_day"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="left|center_vertical"
    android:text="@string/day"
    android:textSize="@dimen/size8" />

<RadioButton
    android:id="@+id/u_week"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="left|center_vertical"
    android:text="@string/week"
    android:textSize="@dimen/size8" />

</LinearLayout>

另外,here 是一个使用RadioGroup 的示例教程。

【讨论】:

  • RadioGroup 实际上是LinearLayout 的子类。
  • 如果我添加一个LinearLayout 并将RadioGroup 放入其中会有帮助吗?
  • 为什么要更改layout_height、showDividers、divider、dividerVertical和dividerPadding?
  • 没有必要。我只是用了一个我已经有的例子。如果你愿意,你可以把这些参数拿出来。
  • 如果我把它放在我创建的额外LinearLayout 中?好吗?
【解决方案2】:

如果错误在某些设备中仍然存在,我还建议使用LinearLayout 而不是RelativeLayout

【讨论】:

    猜你喜欢
    • 2014-01-27
    • 2013-02-06
    • 1970-01-01
    • 1970-01-01
    • 2021-11-13
    • 1970-01-01
    • 2015-06-19
    • 2015-10-20
    • 1970-01-01
    相关资源
    最近更新 更多