gpt4 book ai didi

android - 以编程方式将单选按钮文本添加到按钮顶部

转载 作者:太空狗 更新时间:2023-10-29 16:27:16 24 4
gpt4 key购买 nike

有没有办法像下面这样以编程方式将单选按钮的文本对齐到顶部。

enter image description here

我使用下面的代码创建广播组

  final RadioButton[] rb = new RadioButton[5];
RadioGroup rg = new RadioGroup(getActivity()); //create the RadioGroup
rg.setOrientation(RadioGroup.VERTICAL);//or RadioGroup.VERTICAL
rg.setLayoutParams(radioparams);

for (int i = 0; i < 5; i++) {
rb[i] = new RadioButton(getActivity());
rb[i].setText("Radiobtn " + i);
rb[i].setId(i + 100);
rg.addView(rb[i]);

}
layout.addView(rg);

但我会在每个按钮的右侧获取文本。

最佳答案

    final RadioButton[] rb = new RadioButton[5];
RadioGroup rg = new RadioGroup(getActivity()); //create the RadioGroup
rg.setOrientation(RadioGroup.VERTICAL);//or RadioGroup.VERTICAL
rg.setLayoutParams(radioparams);

for (int i = 0; i < 5; i++) {
rb[i] = new RadioButton(getActivity());
rb[i].setText("Radiobtn " + i);
rb[i].setId(i + 100);
rb[i].setButtonDrawable(null);

TypedArray a = getTheme().obtainStyledAttributes(R.style.AppTheme, new int[] {android.R.attr.listChoiceIndicatorSingle});
int attributeResourceId = a.getResourceId(0, 0);
Drawable drawable = getResources().getDrawable(attributeResourceId);

rb[i].setCompoundDrawablesWithIntrinsicBounds(null, null, null, drawable);
rb[i].setGravity(Gravity.CENTER | Gravity.BOTTOM);
rg.addView(rb[i]);

}
layout.addView(rg);

关于android - 以编程方式将单选按钮文本添加到按钮顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47691493/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com