Я настраиваю RadioGroup с помощью RadioButton, и они все заполняются динамически на основе данных в Firebase.Я устанавливаю параметры следующим образом:
mParams = new RadioGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
mParams.setMargins(0,0,4,6);
Затем я создаю экземпляры своих объектов RadioButton:
public void addRadioButtonsWithFirebaseAnswers(List<DocumentSnapshot> answers) {
mPollAnswerArrayList = new ArrayList<RadioButton>();
int indexCreated = 0;
for (DocumentSnapshot answerSnapshot : answers) {
Answer answer = answerSnapshot.toObject(Answer.class);
mPollAnswerArrayList.add((indexCreated), new RadioButton(mContext));
RadioButton radioButton = mPollAnswerArrayList.get(indexCreated);
radioButton.setTag(indexCreated);
radioButton.setText(answer.getAnswer().toString());
radioButton.setTextColor(getResources().getColor(R.color.black));
radioButton.setButtonDrawable(R.drawable.custom_btn_radio);
//TODO: Investigate if this line is necessary
radioButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.radio_button_answer_text_size));
mPollQuestionRadioGroup.addView(radioButton, mParams);
indexCreated++;
}
}
Ниже показано, как это выглядит.Я хочу добавить пробел между переключателем и текстом.Я также хочу пробел между каждой кнопкой.Наконец, я хотел бы, чтобы текст центрировался кнопкой, если это возможно.
