I would like to add margin or padding to a RadioGroup programmatically but it not working.
RadioButton:
<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_fruit"
android:button="@null"
android:checked="false" />
RadioGroup:
<RadioGroup
android:id="@+id/radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
</RadioGroup>
Java code:
RadioButton radioButtonView = (RadioButton) getActivity().getLayoutInflater().inflate(R.layout.radio_button, null);
radioGroup.addView(radioButtonView);
I tried to use LayoutParams
and dividerPadding
but it not works
Try this
RadioButton radioButtonView = (RadioButton) getLayoutInflater().inflate(R.layout.radio_button, null, false);
RadioGroup.LayoutParams params = new RadioGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.setMargins(15, 15, 15, 15);
radioButtonView.setLayoutParams(params);
radioGroup.addView(radioButtonView);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With