Can not set padding programatically to circular side in RadioButton

21 Views Asked by At

Im creating RadioButton with RTL layout so that the circle drawable will be on the right side. I need to create it programatically because it needs to dynamically added. But i found a problem when trying to give padding on the side in which the circle drawable exist. Whereas this is no problem when creating via xml.

I have tried giving padding while insantiating it like this:

val radioButton = MaterialRadioButton(context).apply {
    id = data.first
    text = data.second
    layoutDirection = LAYOUT_DIRECTION_RTL
    layoutParams = ViewGroup.LayoutParams(
        ViewGroup.LayoutParams.MATCH_PARENT,
        ViewGroup.LayoutParams.WRAP_CONTENT,
    )
    setPadding(0,0, 100,0)
}

Or after it being added to the view.

binding.radioSelection.addView(radioButton)
binding.radioSelection.findViewById<RadioButton>(data.first).updatePadding(
    right = 100,
)

both no luck.

But if i create it using xml it will work. Either using paddingRight in xml or using this:

binding.dummyRadioButton3.updatePadding(
    right = 100,
)

Is it possible things to do or Google just blocked us from doing it?

0

There are 0 best solutions below