gpt4 book ai didi

java - 使用 RadioGroup 和 RadioButtons

转载 作者:太空宇宙 更新时间:2023-11-03 13:37:05 25 4
gpt4 key购买 nike

嘿,我想让 RadioButton 的文本出现在 RadioButton 的左侧。所以我尝试使用 2 个相对 View (我有 2 个 RadioButtons)并且它有效但问题是 RadioGroup 无法正常工作。 . 这是代码:

<RelativeLayout android:id="@+id/SearchRelative" 
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<RadioButton android:checked="true"
android:id="@+id/SearchRadioButtonAloneWord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true">
</RadioButton>

<TextView android:text="1"
android:layout_toLeftOf="@+id/SearchRadioButtonAloneWord"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</RelativeLayout>

<RelativeLayout android:id="@+id/SearchRelative"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<RadioButton android:id="@+id/SearchRadioButtonInBetweenWord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true">
</RadioButton>

<TextView android:text="2"
android:layout_toLeftOf="@+id/SearchRadioButtonInBetweenWord"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</RelativeLayout>

它们可以在其 RadioButton 左侧正确显示文本。但是 RadioGroup 不起作用!
我该如何解决这个问题?
谢谢

Edit1:是否可以动态地将 RadioButton 添加到组中?这是解决我的问题的一种方法!

最佳答案

关于在 RadioGroup 中使用布局管理器:抱歉,它不能那样工作。据我所知,如果将某些内容添加到不是 RadioButton 实例的 RadioGroup,则它不受此 RadioGroup 管理。但这提供了该问题的替代解决方案:扩展 RadioButton 以按照您想要的方式绘制它。

至于动态操作:是的,这可以通过 RadioGroup 实现,就像任何其他 ViewGroup 一样。您所要做的就是通过 RadioGroup.addView() 添加 RadioButton

关于java - 使用 RadioGroup 和 RadioButtons,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5666930/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com