0

I have an XML with a RadioGroup and I'm programmatically adding RadioButton to the RadioGroup. Nevertheless, in my RadioButtons I want to have items with two lines text, such as Category name\nand parent category. Unfortunately, for some reason, the margin/padding isn't kept for the second line.

This is the way I add my button:

RadioButton radioButton = (RadioButton) item.findViewById(R.id.categoryName); radioButton.setText(categoryName + "\n" + parentCategoryText);

This is my button in the XML:

<RadioButton
    android:id="@+id/categoryName"
    style="@style/mpRefineNormalText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@null"
    android:drawablePadding="10dp"
    android:duplicateParentState="true"
    android:ellipsize="end"
    android:maxLines="2"
    android:singleLine="false"
    android:textSize="@dimen/paddingCategoryListItemTextSize"
    tools:text="Category name\nand parent category"/>

How can I fix this?

Thanks a lot in advance!

enter image description here

noloman
  • 11,411
  • 20
  • 82
  • 129

2 Answers2

0

Try This Its working for me

<RadioButton
            android:id="@+id/categoryName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@null"
            android:duplicateParentState="true"
            android:ellipsize="end"
            android:maxLines="2"
            android:singleLine="false"
            android:textSize="14sp"
            tools:text="Category name\nand parent category"
            android:paddingLeft="20dp"/>
Amy
  • 4,034
  • 1
  • 20
  • 34
0

My fault, since when setting the name of the category programmatically, it had some blank spaces before the name, hence the "aggregated" padding to the left of the RadioButton in the first line. Thanks everybody for the replies!

noloman
  • 11,411
  • 20
  • 82
  • 129