RadioGroup 扩展relativelayout?
我正在尝试为我的应用程序制作一个单选按钮网格,据我所知,使用常规 RadioGroup
是不可能的,因为它扩展了 LinearLayout 并且如果您尝试排列 在
RadioGroup
内部使用RelativeLayout 的RadioButtonsRadioGroup
在RelativeLayout
中看不到Buttons
。
因此,为了解决这个问题,我想创建一个扩展RelativeLayout而不是LinearLayout的自定义RadioGroup。
我该怎么做?
更新:我做了你所说的,但我有这些错误,我不知道如何在类文件中修复:
Description Resource Path Location Type
RadioGroup_checkedButton cannot be resolved or is not a field RadioGroupRelative.java /BlockBall/src/com/stickfigs/blockball line 81 Java Problem
The constructor RelativeLayout.LayoutParams(int, int, float) is undefined RadioGroupRelative.java /BlockBall/src/com/stickfigs/blockball line 265 Java Problem
The method setOnCheckedChangeWidgetListener(CompoundButton.OnCheckedChangeListener) is undefined for the type RadioButton RadioGroupRelative.java /BlockBall/src/com/stickfigs/blockball line 363 Java Problem
The method setOnCheckedChangeWidgetListener(null) is undefined for the type RadioButton RadioGroupRelative.java /BlockBall/src/com/stickfigs/blockball line 377 Java Problem
VERTICAL cannot be resolved to a variable RadioGroupRelative.java /BlockBall/src/com/stickfigs/blockball line 68 Java Problem
Widget_CompountButton_RadioButton cannot be resolved or is not a field RadioGroupRelative.java /BlockBall/src/com/stickfigs/blockball line 79 Java Problem
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要从 RadioGroup 的源代码href="http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/widget/RadioGroup.java;h=393346a314f7b1ad20c617c494904f599391c081;hb= HEAD" rel="noreferrer">此处,替换所有条目
LinearLayout
与RelativeLayout
。将此代码添加到项目中的某个 xml 文件中(通常其名称为 attrs.xml):
将
RadioGroup
的构造函数替换为以下内容:从
LayoutParams
内部删除以下构造函数类:将所有出现的
setOnCheckedChangeWidgetListener()
方法调用替换为setOnCheckedChangeListener()
方法。 重要:在这种情况下,将无法在使用此小部件的代码中使用此方法。还没有尝试过,但希望这会起作用。
You need to get the
RadioGroup
's source code from here, replace all entries ofLinearLayout
withRelativeLayout
.Add this code to some xml file in your project (usually its name is attrs.xml):
Replace
RadioGroup
's constructors with these:Remove the following constructor from the
LayoutParams
inner class:Replace all occurrences of
setOnCheckedChangeWidgetListener()
method calls with thesetOnCheckedChangeListener()
method. IMPORTANT: In this case it won't be possible to use this method from a code that uses this widget.Haven't tried this but hope this will work.
从 这里并编辑它以将其更改为扩展RelativeLayout而不是LinearLayout。
Copy the source for RadioGroup from here and edit it to change it to extend RelativeLayout instead of LinearLayout.
这超出了主题,但如果您想使用
ConstraintLayout
做同样的事情,那么代码是 Github 上提供您可以导入库并使用小部件
ConstraintRadioGroup
This is out of topic, but in case if you wanna do the same thing with
ConstraintLayout
then the code is available at GithubYou can import the library and use the widget
ConstraintRadioGroup