Android 设置运行时创建的单选按钮之间的间距/边距

Android 设置运行时创建的单选按钮之间的间距/边距,android,android-radiobutton,Android,Android Radiobutton,我正在用代码创建自定义单选按钮。这是定制的radioButton类 public class SurveyRadioButton extends RadioButton { private int value; private int questionId; public SurveyRadioButton(Context context) { super(context); setBackgroundResource(R.drawable.selector_checkbo

我正在用代码创建自定义单选按钮。这是定制的radioButton类

public class SurveyRadioButton extends RadioButton {

private int value;
private int questionId;

public SurveyRadioButton(Context context) {
    super(context);

    setBackgroundResource(R.drawable.selector_checkbox);

    setButtonDrawable(new StateListDrawable());

    setPadding(10, 20, 10, 20);

    setTextSize(17);

}


public int getValue() {
    return value;
}

public void setValue(int value) {
    this.value = value;
}

public int getQuestionId() {
    return questionId;
}

public void setQuestionId(int questionId) {
    this.questionId = questionId;
}
}

接下来就是创建脚本

LinearLayout.LayoutParams matchWrapLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);


LinearLayout root = (LinearLayout) findViewById(R.id.root);

    RadioGroup radioGroup = new RadioGroup(SplashActivity.this);

    radioGroup.setLayoutParams(matchWrapLayoutParams);

    {
        for (int ii = 0; ii < 5; ii++) {


            SurveyRadioButton radioButton = new SurveyRadioButton(this);

            radioButton.setLayoutParams(matchWrapLayoutParams);

            radioButton.setText("arda");

            radioButton.setSelected(false);

            radioGroup.addView(radioButton);
        }

        root.addView(radioGroup);

    }
LinearLayout.LayoutParams matchWrapLayoutParams=新的LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_父级,ViewGroup.LayoutParams.WRAP_内容);
LinearLayout root=(LinearLayout)findViewById(R.id.root);
放射组放射组=新放射组(SplashActivity.this);
radioGroup.setLayoutParams(matchWrapLayoutParams);
{
对于(int ii=0;ii<5;ii++){
SurveyRadioButton radioButton=新的SurveyRadioButton(本);
radioButton.setLayoutParams(matchWrapLayoutParams);
radioButton.setText(“arda”);
radioButton.setSelected(假);
radioGroup.addView(单选按钮);
}
root.addView(放射组);
}
这些代码可以显示这些视图,但我想在单选按钮之间添加间距。在布局参数中设置边距无效。我想知道会是什么


我找不到任何聪明的解决办法。但将空白视图添加到radiogroup可以处理此问题

        SurveyRadioButton radioButton = new SurveyRadioButton(this);

        radioButton.setLayoutParams(matchWrapLayoutParams);

        radioButton.setText("arda");

        radioButton.setSelected(false);

        radioGroup.addView(radioButton);

        //Above 4 rows for blank view
        View blankView = new View(QuestionActivity.this);

        LinearLayout.LayoutParams matchWrapLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 20);

        blankView.setLayoutParams(matchWrapLayoutParams);

        radioGroup.addView(blankView);

我找不到任何聪明的解决办法。但将空白视图添加到radiogroup可以处理此问题

        SurveyRadioButton radioButton = new SurveyRadioButton(this);

        radioButton.setLayoutParams(matchWrapLayoutParams);

        radioButton.setText("arda");

        radioButton.setSelected(false);

        radioGroup.addView(radioButton);

        //Above 4 rows for blank view
        View blankView = new View(QuestionActivity.this);

        LinearLayout.LayoutParams matchWrapLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 20);

        blankView.setLayoutParams(matchWrapLayoutParams);

        radioGroup.addView(blankView);