3

I don’t know why my RadioGroup dividers are not showing. Will someone please shed some light. I already looked at Android radiogroup, divider between radiobuttons.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:divider="@drawable/divider_color"
        android:showDividers="middle" >

        <RadioButton
            android:id="@+id/first"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:button="@null"
            android:checked="true"
            android:drawableRight="@android:drawable/btn_radio"
            android:text="First" />

        <RadioButton
            android:id="@+id/second"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:button="@null"
      android:drawableRight="@android:drawable/btn_radio"
      android:text="second" />

        <RadioButton
            android:id="@+id/third"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:button="@null"
      android:drawableRight="@android:drawable/btn_radio"
      android:text="third" />
    </RadioGroup>

</LinearLayout>

My shape for divider_color is

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line" >

    <solid android:color="#000000" />

</shape>
Community
  • 1
  • 1
learner
  • 11,490
  • 26
  • 97
  • 169
  • Try this answer: http://stackoverflow.com/a/17693303/2649012. But Akram's comment is also a valid alternative. – Phantômaxx Jun 20 '14 at 16:47
  • @DerGolem That answer won't work for me: I only need the middle lines. And I know it must be possible because Google uses it in the Play Store to let users mark comments as spam or helpful. – learner Jun 20 '14 at 17:00
  • Did you read Akram's comment? Since RadioGroup inherits from LinearLayout, you can add **generic Views in between the RadioButtons**. Each View would feature a colored background. And you need **n-1** generic Views, being n the number of your RadioButtons. – Phantômaxx Jun 20 '14 at 17:25
  • 1
    @DerGolem I missed that comment. But that's correct, it works. Thanks. If you don't mind, will you post a response so I might mark this post as answered. But please talk about the linear layout part so other people looking can find it in a more obvious way. Thanks. – learner Jun 20 '14 at 19:57
  • Done. Feel free to experiment with the drawable you will use for the Views background – Phantômaxx Jun 21 '14 at 07:43
  • It is worth mentioning that the divider **should be drawable not a color**. I spent 1 hour in figuring out why it wasn't working. If you need a black line, just **create a drawable shape of black line**. – Rohan Kandwal Aug 16 '16 at 08:59

1 Answers1

1
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line" >

    <stroke
        android:width="1dp"
        android:color="#000000" />
    <size android:height="2dip" />
</shape>

update your drawable like above or use below one

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<size android:height="1dp"></size>
<solid android:color="#000000" />

44kksharma
  • 2,740
  • 27
  • 32