java在单选按钮drawable的左侧添加填充
我试图在单选按钮的左侧添加填充。但实际上,在可绘制和文本之间添加了填充
我创建单选按钮的方法:
private RadioButton createRadioButton(String text) {
RadioButton btn = new RadioButton(requireContext());
btn.setId(View.generateViewId());
btn.setText(text);
btn.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
btn.setTextColor(answerButtonColor);
btn.setButtonTintList(answerButtonColor);
int pxHorizontal = Utils.convertDpToPx(requireContext(), 24);
int pxVertical = Utils.convertDpToPx(requireContext(), 16);
btn.setPadding(pxHorizontal, pxVertical, pxHorizontal, pxVertical);
btn.setLayoutParams(new RadioGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
));
return btn;
}
有没有办法在单选按钮的左侧添加填充
# 1 楼答案
RadioButton是CompundButton的一个子类,因此我们可以在复合按钮上绘制,并向其添加插图