4

As you can see, I got a simple RadioGroup and its options.

<RadioGroup
    android:id="@+id/radio_report_problems"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="20dp" >

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

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

    .....

</RadioGroup>

My problem is that the bullet sits at the middle of the text, instead of starting at the first line

printscreen

Without using tableView, or linearLayout, is there a simple way to achieve this using RadioGroup only?

Thank you.

neoswf
  • 4,730
  • 6
  • 39
  • 59

3 Answers3

5

i used

android:gravity="top"

and it works

see this: enter image description here

M Moersalin
  • 290
  • 3
  • 12
3

You could extend RadioButton and override the onDraw method to draw the button aligned with the top of the text. The code for drawing that button is actually inside of CompoundButton (RadioButton extends from that), so that should be your starting point for how to draw the button. Source

Personally I don't think there's anything wrong with the button aligning to the center, but that's beside the point.

Karakuri
  • 38,365
  • 12
  • 84
  • 104
  • In HTML the default is vertical aligned to the top. I come from client side, and its just seems more clean for me. Is it common in ```Android``` to have lists positioned like that? Thanks for your answer. Isn't there's a simpler way than this? – neoswf Jul 08 '14 at 16:56
  • 2
    This is just how Android's RadioButton (and CompoundButton) behaves, and I doubt anyone other than the actual developers would know why that is, or why there's no affordance for aligning the button differently. I've often made custom Views that are only minor modifications of existing ones, and unfortunately I can't think of a simpler way to get the effect you want. – Karakuri Jul 08 '14 at 17:07
  • The `onDraw` method is `protected`. That means you cannot override in your class that extends `RadioButton`. – Raquib-ul Alam Aug 19 '18 at 15:28
  • @AlamKanak You absolutely can override `onDraw`. (For that matter, when you subclass, you can absolutely override any `protected` method of the superclass.) – Karakuri Aug 20 '18 at 14:51
-2

set gravity top | bottom for radio button

radioButton.setGravity(Gravity.TOP | Gravity.BOTTOM);
Adrian Tandrau
  • 13
  • 1
  • 2
  • 7