2016-06-13 3 views
1

コードでカスタムラジオボタンを作成しています。ここでは、カスタム、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); 

    } 

を作成しそこに行く見解ことになりますが、私はラジオボタンの間のギャップを追加します。レイアウトパラメータにマージンを設定しても機能しません。私は何があるのだろうと思っていますか?

enter image description here

答えて

0

私は、任意の巧妙な解決策を見つけることができませんでした。しかし、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); 
関連する問題