Or B
Or B

Reputation: 1803

Android Radio Button Text Is Misplaced

I have created a layout which contains some RadioGroups and RadioButtons. The RadioGroups' parent layout is RelativeLayout, and if it's possible I would like to stay with RelativeLayout.

In most of the devices, the circle of the RadioButton is in the left of the text, as it has to be, like this:

enter image description here

But in some devices (I noticed the problem with Samsung devices that are set to Hebrew), the circle is actually on the text, like this:

enter image description here

Here is my code (I deleted other items in the layout which are irrelevant):

<?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>

I have found nothing helpful with this problem, could please someone show me the way to solve it?

Upvotes: 1

Views: 467

Answers (2)

Luis Lavieri
Luis Lavieri

Reputation: 4129

The problem is that you are using RelativeLayout. Try using LinearLayout instead. This is the one that is used to arrange objects horizontally or vertically. Check the guides or examples; there are many out there.

I would try it like this:

<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>

Also, here is a tutorial with an example using a RadioGroup.

Upvotes: 1

Sash_KP
Sash_KP

Reputation: 5591

I also would recommend to use LinearLayout instead of RelativeLayout if the bug persists in some devices.

Upvotes: 0

Related Questions