RadioGroup扩展了RelativeLayout吗?

| 我正在尝试为我的应用程序制作一个单选按钮网格,据我了解到,使用常规
RadioGroup
是不可能的,因为它扩展了LinearLayout,并且如果您尝试使用RelativeLayout将
RadioButtons
布置在
RadioGroup
ѭ0内在
RelativeLayout
中看不到
Buttons
。 因此,为了解决此问题,我想制作一个自定义的RadioGroup,它扩展了RelativeLayout而不是LinearLayout。 我该怎么做呢? 更新:我按照您的意思做了,但是我有这些错误,我不知道如何在类文件中修复:
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
    
已邀请:
        您需要从此处获取
RadioGroup
的源代码,并将
LinearLayout
的所有条目替换为
RelativeLayout
。 将此代码添加到项目中的某些xml文件中(通常其名称为attrs.xml):
<resources>
    <declare-styleable name=\"RadioGroup\">
        <attr name=\"android:checkedButton\" />
    </declare-styleable>
</resources>
将0的构造函数替换为:
public RadioGroup(Context context) {
    super(context);
    if (!isInEditMode()) {
        init();
    }
}

public RadioGroup(Context context, AttributeSet attrs) {
    super(context, attrs);
    if (!isInEditMode()) {
        TypedArray attributes = context.obtainStyledAttributes(
                attrs, R.styleable.RadioGroup, 0,
                android.R.style.Widget_CompoundButton_RadioButton);

        int value = attributes.getResourceId(R.styleable.RadioGroup_checkedButton,
            View.NO_ID);
        if (value != View.NO_ID) {
            mCheckedId = value;
        }

        attributes.recycle();
        init();
    }
}
LayoutParams
内部类中删除以下构造函数:
public LayoutParams(int w, int h, float initWeight) {
    super(w, h, initWeight);
}
将所有出现的
setOnCheckedChangeWidgetListener()
方法调用替换为
setOnCheckedChangeListener()
方法。重要说明:在这种情况下,将无法从使用此小部件的代码中使用此方法。 还没有尝试过,但希望能成功。     
        从此处复制RadioGroup的源,并对其进行编辑以进行更改以扩展RelativeLayout而不是LinearLayout。     

要回复问题请先登录注册