Android radiogroup, divider between radiobuttons(Android radiogroup,单选按钮之间的分隔符)
问题描述
有没有一种简单的方法可以在 RadioGroup 内的 RadioButtons 之间添加分隔线?我尝试使用 divider xml 属性,但它似乎不起作用.如果相关,我的布局中的 RadioGroup 不包含任何子视图;我正在以编程方式添加 RadioButtons.
Is there a simple way to add a divider between RadioButtons inside a RadioGroup? I've tried using the divider xml attribute and it doesn't seem to be working. In case it's relevant, the RadioGroup in my layout does not contain any child views; I'm adding the RadioButtons programmatically.
编辑:问题已解决.您可以在 xml 中的 RadioGroup 内添加除 RadioButton 之外的视图.在我的情况下,您也可以通过编程方式执行此操作,但请注意您的布局参数.Akki 有正确的想法,这对我有用:
EDIT: Problem solved. You can add views besides RadioButton inside RadioGroup in the xml. In my case, you can also do it programmatically, but be careful about your layout params. Akki had the right idea, and this worked for me:
for (int i = 0; i < items.size(); i++) {
if (i > 0) {
// add a divider with height of 1 pixel
View v = new View(this);
v.setLayoutParams(new RadioGroup.LayoutParams(LayoutParams.MATCH_PARENT, 1));
v.setBackgroundColor(android.R.color.darker_gray);
mRadioGroup.addView(v);
}
RadioButton rb = new RadioButton(this);
/* set other properties ... */
mRadioGroup.addView(rb);
}
推荐答案
<RadioGroup
android:id="@+id/location_radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="?android:attr/dividerHorizontal"
android:showDividers="middle">
</RadioGroup>
这对你有用.我真的很好奇您如何将视图添加到组视图中?那应该导致classcastexception,不是吗?
That will work for you. And I am really curious how you add view into Group View? That should cause classcastexception, no ?
这篇关于Android radiogroup,单选按钮之间的分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android radiogroup,单选按钮之间的分隔符
基础教程推荐
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
