【发布时间】:2018-12-01 15:48:35
【问题描述】:
我正在使用 RadioButtons 设置 RadioGroup,它们都是根据 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++;
}
}
下面是它的外观。我想在单选按钮和文本之间添加空格。我还想要每个按钮之间的空间。最后,如果可能的话,我希望文本以按钮为中心。
【问题讨论】:
标签: android xml radio-button