您需要获得RadioGroup
的源代码来自here http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/widget/RadioGroup.java;h=393346a314f7b1ad20c617c494904f599391c081;hb=HEAD,替换所有条目LinearLayout
with RelativeLayout
.
将此代码添加到项目中的某个 xml 文件中(通常其名称为 attrs.xml):
<resources>
<declare-styleable name="RadioGroup">
<attr name="android:checkedButton" />
</declare-styleable>
</resources>
Replace RadioGroup
的构造函数有这些:
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()
方法。重要的:在这种情况下,无法从使用此小部件的代码中使用此方法。
还没有尝试过,但希望这会起作用。