0

I want to align my radio buttons in front of each other. My radio buttons are in the radio group and my parent layout is a constraint layout.

How to do that? I tried by putting the radio group into a child relative layout but it's not working. I want to align my radio buttons in front of each other.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
    tools:context=".MainActivity">


    <EditText
        android:id="@+id/mValidity"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"[In image you can see get now radio button is below the shop now radio button. but i want get now radio button will be in right of hop now.][1]
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/mLink"
        app:layout_constraintVertical_bias="0.000" />

    <RadioGroup
        android:id="@+id/lRadioGroup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/mValidity"
        app:layout_constraintVertical_bias="0.000">

        <RadioButton
            android:id="@+id/mShopNow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:onClick="checkButton"
            android:text="SHOP NOW" />

        <RadioButton
            android:id="@+id/mGetNow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="checkButton"
            android:text="GET NOW" />

    </RadioGroup>

    <TextView
        android:id="@+id/mDealType"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Deal Type"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/lRadioGroup"
        app:layout_constraintVertical_bias="0.000" />

    <Button
        android:id="@+id/btn"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:onClick="addNote"
        android:text="Insert Document"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/mDealType"
        app:layout_constraintVertical_bias="0.035" />

</androidx.constraintlayout.widget.ConstraintLayout>
Pranav P
  • 1,755
  • 19
  • 39
  • Can you add image of your layout file? so it can be more understandable. – Pranav P May 28 '20 at 02:21
  • here is the link of image.. https://drive.google.com/file/d/1_TWDF3-QNG_4hVIhfbFoeW2JoKRv0nkt/view?usp=sharing I want that get now radio button in front of shop now radio button – Deeksha Sharma May 28 '20 at 11:13

1 Answers1

0

you can give orientation = horizontal to RadioGroup like this

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
    tools:context=".MainActivity">

    <EditText
        android:id="@+id/mValidity"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/mLink"
        app:layout_constraintVertical_bias="0.000" />

    <RadioGroup
        android:id="@+id/lRadioGroup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/mValidity">

        <RadioButton
            android:id="@+id/mShopNow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:gravity="center|right"
            android:onClick="checkButton"
            android:text="SHOP NOW"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <RadioButton
            android:id="@+id/mGetNow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="20dp"
            android:gravity="center|right"
            android:onClick="checkButton"
            android:text="GET NOW"
            app:layout_constraintStart_toEndOf="@+id/mShopNow"
            app:layout_constraintTop_toTopOf="@+id/mShopNow" />

    </RadioGroup>

    <TextView
        android:id="@+id/mDealType"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Deal Type"
        android:visibility="gone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/lRadioGroup"
        app:layout_constraintVertical_bias="0.000" />

    <Button
        android:id="@+id/btn"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:onClick="addNote"
        android:text="Insert Document"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/mDealType"
        app:layout_constraintVertical_bias="0.035" />

</androidx.constraintlayout.widget.ConstraintLayout>
Shweta Chauhan
  • 6,739
  • 6
  • 37
  • 57