我想将单选按钮彼此对齐。我的单选按钮在单选组中,而我的父布局是约束布局。
该怎么做?我尝试通过将无线电广播组放入相对于儿童的相对布局,但无法正常工作。我想将单选按钮彼此对齐。
<?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>
您可以像这样向RadioGroup定向
<?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>