问题描述
I am trying to achieve this while working with radio buttons
我尝试通过遵循XML代码来执行相同的操作,但是失败了,因为它无法返回单选按钮ID。 我添加了约束布局,以便可以自定义,但看起来是在创建问题。
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="10dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="10dp"
android:dividerPadding="10dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cs"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioButton
android:id="@+id/short_mom"
style="@style/Widget.AppCompat.CompoundButton.RadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:checked="true"
android:onClick="onCLick"
android:paddingLeft="32sp"
android:text="shortMoM"
app:layout_constraintBottom_toBottomOf="@+id/short_mom_pic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/short_mom_pic" />
<ImageView
android:id="@+id/short_mom_pic"
android:layout_width="0dp"
android:layout_height="180sp"
android:layout_marginStart="64dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="16dp"
android:scaleType="centerInside"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/short_mom" />
<RadioButton
android:id="@+id/briefMom"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingLeft="32sp"
android:text="longMoM"
app:layout_constraintBottom_toBottomOf="@+id/brief_mom_pic"
app:layout_constraintEnd_toEndOf="@+id/short_mom"
app:layout_constraintStart_toStartOf="@+id/short_mom"
app:layout_constraintTop_toTopOf="@+id/brief_mom_pic" />
<ImageView
android:id="@+id/brief_mom_pic"
android:layout_width="0dp"
android:layout_height="180sp"
android:layout_marginTop="32dp"
app:layout_constraintEnd_toEndOf="@+id/short_mom_pic"
app:layout_constraintStart_toStartOf="@+id/short_mom_pic"
app:layout_constraintTop_toBottomOf="@+id/short_mom_pic"
app:srcCompat="@drawable/brief_mom_pic" />
</androidx.constraintlayout.widget.ConstraintLayout>
</RadioGroup>
我尝试通过使用单选按钮的drawable选项执行相同的操作,但是自定义变得很困难。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)