0

My RadioButtons are slightly above the text attached with them. As shown in the figure, how to resolve this issue?

I want buttons to be positioned as normal. Which means the RadioButton circle should be visible in the middle alignment to the text written in front of it.

enter image description here

Following is the activity_main.xml file code:

<?xml version="1.0" encoding="utf-8"?>



<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:background="@layout/backrepeat"
    tools:context=".MainActivity">

    <RadioGroup
        android:id="@+id/radioGroup"
        android:layout_width="368dp"
        android:layout_height="47dp"
        android:layout_gravity="end"
        android:layout_marginStart="8dp"
        android:layout_marginTop="12dp"
        android:background="@color/colorPrimaryDark"
        android:orientation="horizontal"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/editText">

        <RadioButton
            android:id="@+id/azadRadio"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="start"
            android:layout_weight="1"
            android:gravity="right"
            android:layoutDirection="rtl"
            android:text="آزاد"
            android:textColor="?attr/colorBackgroundFloating"
            android:textSize="25sp" />

        <RadioButton
            android:id="@+id/qafiaRadio"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="start"
            android:layout_weight="1"
            android:gravity="right"
            android:layoutDirection="rtl"
            android:text="قافیہ"
            android:textColor="?attr/colorBackgroundFloating"
            android:textSize="25sp" />

        <RadioButton
            android:id="@+id/sabiqaRadio"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="start"
            android:layout_weight="1"
            android:gravity="right"
            android:textColor="?attr/colorBackgroundFloating"
            android:layoutDirection="rtl"
            android:text="سابقہ"
            android:textSize="25sp" />
    </RadioGroup>


    <EditText
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="44dp"
        android:layout_marginTop="16dp"
        android:ems="10"
        android:inputType="text"
        app:layout_constraintStart_toEndOf="@+id/button"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="8dp"
        android:onClick="Finder"
        android:text="تلاش"
        android:textSize="20sp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ListView
        android:id="@+id/listView"
        android:layout_width="359dp"
        android:layout_height="377dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="8dp"

        android:scrollbarSize="22dip"

        android:scrollbarThumbVertical="@color/colorPrimaryDark"
        android:scrollbars="vertical"
        android:verticalScrollbarPosition="left"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/radioGroup" />

</android.support.constraint.ConstraintLayout>
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Code
  • 61
  • 1
  • 11

2 Answers2

2
<RadioButton
    ...
    android:textAlignment="center"
    ... />

That should align the text of the radio button in the center which should position the text according to your criteria.

Nero
  • 1,058
  • 1
  • 9
  • 25
0

When you align right with gravity="right" which implicitly aligned button right/top, You can override that with add flag center besides right.

<RadioButton
   ...
   android:gravity="right|center"
   ... />
Khaled Lela
  • 7,831
  • 6
  • 45
  • 73