Android 它';可以将文本视图放在放射组中。但是,这是好的做法吗?

Android 它';可以将文本视图放在放射组中。但是,这是好的做法吗?,android,radio-button,Android,Radio Button,我试图实现的目标:当用户单击特定的RadioButton时,所选RadioButton的正下方会出现一个文本视图 到目前为止我的解决方案:在代码方面,将文本视图放在RadioGroup内,并将其初始可见性设置为“不可见”。然后,单击特定单选按钮时,将隐藏文本视图的可见性设置为“可见”。取消选中单选按钮时,隐藏文本视图。设置TextView的可见性是在我定义的活动类中完成的 因此,在下面的示例XML代码中,当选择“单选按钮”时,“my\u有时\u hidden\u textview”应该出现。相反

我试图实现的目标:当用户单击特定的RadioButton时,所选RadioButton的正下方会出现一个文本视图

到目前为止我的解决方案:在代码方面,将文本视图放在RadioGroup内,并将其初始可见性设置为“不可见”。然后,单击特定单选按钮时,将隐藏文本视图的可见性设置为“可见”。取消选中单选按钮时,隐藏文本视图。设置TextView的可见性是在我定义的活动类中完成的

因此,在下面的示例XML代码中,当选择“单选按钮”时,“my\u有时\u hidden\u textview”应该出现。相反,当取消选择(或未选择)“单选按钮”时,“我的隐藏文本视图”的可见性应设置为“不可见”

问题:将文本视图放在RadioGroup中是否有效(或良好做法)?如果没有,有没有更好的方法来完成我的目标?我对Android开发比较陌生,所以如果Android官方文档中有什么我遗漏的,请告诉我。感谢您提前提供的见解

main.xml


感谢您的回复、Commonware和Macarse

Commonware:感谢您澄清RadioGroup是一种线性布局。我本能地反对添加TextView,因为迄今为止我遇到的大多数RadioGroup示例都没有显示除单选按钮之外的其他元素。因此,我认为只有单选按钮才能进入放射组

麦卡斯:

  • 正如您所描述的,我尝试将TextView放置在RadioGroup之外。只要程序员不需要文本区域显示在特定单选按钮的正下方,您的解决方案就可以工作。如果不将TextView显式放置在RadioGroup中,我就无法确定如何将TextArea定位在特定RadioButton的正下方

  • 谢谢你的ViewStub链接。事实上,这可能是实现我总体目标的最佳方式。除了我在问题中提到的TextView之外,我还想添加一个按钮,使其仅在选中特定单选按钮时显示在TextView旁边

  • 两种选择:

  • 执行与您所说类似的操作,但不需要位于
    RadioGroup
    中。当用户单击
    单选按钮时,使
    文本视图
    可见
  • 也许您可以使用
    ViewStub
    执行一些操作。检查链接
  • 正在将TextView放在 放射组有效(或良好实践)


    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>