Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android RadioButton issue in android 4

I have a simple application. The screen is build inside a RelativeLayout. I have more LinearLayout(s), one of them shows the 2 RadioButton(s), like this:

        <LinearLayout android:layout_width="match_parent" android:layout_height="fill_parent"
            android:padding="3dp" android:gravity="center">
            <RadioGroup android:id="@+id/rgrDayToReport" 
                android:orientation="horizontal" 
                android:layout_width="wrap_content" android:layout_height="wrap_content">
                <RadioButton android:checked="true" android:id="@+id/rbtnToday"
                    android:layout_width="wrap_content" android:layout_height="wrap_content"

                    android:text="@string/radioTodayText"/>
                <RadioButton  android:id="@+id/rbtnYesterday"
                    android:layout_width="wrap_content" android:layout_height="wrap_content"

                    android:text="@string/radioYesterdayText"/>
            </RadioGroup>
        </LinearLayout>

This panel render correctly in any device (as I did tests) except Samsung Galaxy s3. On this device (only on this device) the screen looks like this:

enter image description here

How should I fix this?

like image 868
Zelter Ady Avatar asked Dec 16 '12 13:12

Zelter Ady


People also ask

How do you check whether a RadioButton is checked or not in android?

Checking Current State Of Radio Button: You can check the current state of a radio button programmatically by using isChecked() method. This method returns a Boolean value either true or false. if it is checked then returns true otherwise returns false.

How can I get RadioButton text in Android?

To get the selected radio button, we have used radioGroup. getCheckedRadioButtonId() method, which returns the id of the selected radio button. Then to get the text of the selected radio button, we have used getText() method on that selected radio button.

What is RadioButton Android studio?

Radio buttons allow the user to select one option from a set. You should use radio buttons for optional sets that are mutually exclusive if you think that the user needs to see all available options side-by-side. If it's not necessary to show all options side-by-side, use a spinner instead.

How do I toggle radio button in Android?

If you are only using one radio box for checking on and off, maybe you should use checkbox or toggle button instead. Scroll down and see checkbox and toggle button. When using radios you usually have more than one and choose between them.


2 Answers

I was experiencing the same problem. I have solved this by NOT setting paddingLeft on RadioButtons and CheckBoxes - leaving default value. paddingLeft was counted from the drawable on all phones and from left corner on Galaxy S3. Also setting background was causing the same bug on Galaxy S3. After leaving default values it's now usable everywhere.

like image 83
David Vávra Avatar answered Oct 09 '22 01:10

David Vávra


This might be too late, but i had the same problem and it was solved by specifying a android:drawableRight or android:drawableLeft, instead of android:button which is set by default

like image 38
elmorabea Avatar answered Oct 09 '22 01:10

elmorabea