Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12201

Aligning the radio buttons with the radio button text in android

$
0
0

This is the design for my radio button in a radio group. The dynamic text that is updated programmatically, it is divided into two lines.The radio button here is aligned to the top of the radio button text whereas I want it to align in the middle android.

<RadioGroup            android:id="@+id/radio_group"            android:layout_width="0dp"            android:layout_height="wrap_content"            android:layout_marginTop="@dimen/dp_32"            android:layout_marginStart="@dimen/dp_16"            android:layout_marginEnd="@dimen/dp_16"            android:orientation="vertical"            android:paddingStart="@dimen/dp_1"            android:paddingEnd="@dimen/dp_1"            android:background="@drawable/radio_group_rectangle"            app:layout_constraintTop_toBottomOf="@+id/title"            app:layout_constraintStart_toStartOf="parent"            app:layout_constraintEnd_toEndOf="parent"></RadioGroup>

This is how the radio buttons are added programatically

 private fun addRadioButtons(){            Enum.values().forEach {            val radioButton = RadioButton(context)            radioButton.layoutParams= LinearLayout.LayoutParams(                ViewGroup.LayoutParams.MATCH_PARENT,                ViewGroup.LayoutParams.WRAP_CONTENT)            TextUtils.setTextToRadioButtons(requireContext(),radioButton,getString(viewModel.getOptions(it.days)),                viewModel.getDateRange(it.days))                radioButton.background = AppCompatResources.getDrawable(requireContext(),R.drawable.radio_button_rectangle)            if (it.days == 14) radioButton.isChecked = true            radioButton.id = it.days            binding.radioGroup.addView(radioButton)        }    }

radio_button_rectangle:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"><!-- This is the line --><item android:top="-2dp" android:right="-2dp" android:left="-2dp"><shape><solid android:color="@android:color/transparent" /><stroke android:width="1dp" android:color="@color/divider" /></shape></item></layer-list>

radio_group_rectangle:

<shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle"><stroke android:width="@dimen/dp_1" android:color="@color/divider"/><solid android:color="@color/transparent"/><corners android:radius="5dp"/></shape>

I have tried adding the Gravity.CENTER as well but the alignment does not change.Could you please let me know how to achieve as the below the screenshot

enter image description here


Viewing all articles
Browse latest Browse all 12201

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>