Android 它';可以将文本视图放在放射组中。但是,这是好的做法吗?
我试图实现的目标:当用户单击特定的RadioButton时,所选RadioButton的正下方会出现一个文本视图 到目前为止我的解决方案:在代码方面,将文本视图放在RadioGroup内,并将其初始可见性设置为“不可见”。然后,单击特定单选按钮时,将隐藏文本视图的可见性设置为“可见”。取消选中单选按钮时,隐藏文本视图。设置TextView的可见性是在我定义的活动类中完成的 因此,在下面的示例XML代码中,当选择“单选按钮”时,“my\u有时\u hidden\u textview”应该出现。相反,当取消选择(或未选择)“单选按钮”时,“我的隐藏文本视图”的可见性应设置为“不可见” 问题:将文本视图放在RadioGroup中是否有效(或良好做法)?如果没有,有没有更好的方法来完成我的目标?我对Android开发比较陌生,所以如果Android官方文档中有什么我遗漏的,请告诉我。感谢您提前提供的见解 main.xmlAndroid 它';可以将文本视图放在放射组中。但是,这是好的做法吗?,android,radio-button,Android,Radio Button,我试图实现的目标:当用户单击特定的RadioButton时,所选RadioButton的正下方会出现一个文本视图 到目前为止我的解决方案:在代码方面,将文本视图放在RadioGroup内,并将其初始可见性设置为“不可见”。然后,单击特定单选按钮时,将隐藏文本视图的可见性设置为“可见”。取消选中单选按钮时,隐藏文本视图。设置TextView的可见性是在我定义的活动类中完成的 因此,在下面的示例XML代码中,当选择“单选按钮”时,“my\u有时\u hidden\u textview”应该出现。相反
感谢您的回复、Commonware和Macarse Commonware:感谢您澄清RadioGroup是一种线性布局。我本能地反对添加TextView,因为迄今为止我遇到的大多数RadioGroup示例都没有显示除单选按钮之外的其他元素。因此,我认为只有单选按钮才能进入放射组 麦卡斯:
RadioGroup
中。当用户单击单选按钮时,使文本视图
可见
ViewStub
执行一些操作。检查链接RadioGroup
只是一个LinearLayout
,它碰巧也处理RadioButton
排除规则(即,“只能有一个……已选中”)。我认为在RadioGroup
中使用TextView
没有特别的问题是的,可以检查这种方法
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/radioGroup"
android:orientation="horizontal">
<RadioButton
android:id="@+id/ifsc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ifsc"
android:textAllCaps="true" />
<Textview
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/appName"
android:id="@+id/ifsc_info"
android:baselineAlignBottom="true"
android:layout_toEndOf="@+id/ifsc" />
</RadioGroup>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/radioGroup"
android:orientation="horizontal">
<RadioButton
android:id="@+id/ifsc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ifsc"
android:textAllCaps="true" />
<Textview
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/appName"
android:id="@+id/ifsc_info"
android:baselineAlignBottom="true"
android:layout_toEndOf="@+id/ifsc" />
</RadioGroup>