2016-06-13 3 views
1

Ich erstelle benutzerdefinierte Radiobuttons in Code. Hier ist die individuelle Radiobutton-KlasseEinstellung von Abstand/Abstand zwischen Radiobuttons, die durch die Laufzeit erstellt werden

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; 
} 

}

und es geht Skript erstellen

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); 

    } 

Diese Codes macht, dass die Ansichten, aber ich Lücke zwischen Radiobuttons hinzufügen möchten. Rand in die Layout-Parameter einstellen funktioniert nicht. Ich frage mich, was wird sein?

enter image description here

Antwort

0

Ich konnte keine clevere Lösung finden. Dies wird jedoch durch Hinzufügen einer leeren Ansicht zu radiogruppe erledigt.

 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); 
Verwandte Themen