RadioGroup中动态添加RadioButton
来源:互联网 发布:百知尚行是培训机构吗 编辑:程序博客网 时间:2024/05/17 03:14
今天写代码遇到一个问题,动态添加的RadioButton设置间距没反应,代码如下:
<span style="white-space:pre"></span>for (int i = 0; i < grades.size(); i++) {RadioButton rb = new RadioButton(getApplicationContext());LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);rb.setButtonDrawable(R.color.transparent);// 去掉radiobutton前边的按钮rb.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);params.setMargins(0,10, 0,0);rb.setLayoutParams(params);rg.addView(rb);}
后来查资料,把LayoutParams 改成RadioGroup.LayoutParams就好了
你可以看一下出错前你LayoutParams 引用的是哪个包,应该是android.widget.LinearLayout.LayoutParams,但是你的radiobutton是在radiogroup下的,所以设置间距没反应
0 0
- RadioGroup中动态添加RadioButton
- android中radioGroup动态添加radioButton
- RadioGroup中动态添加RadioButton,RadioButton状态紊乱
- RadioGroup中添加RadioButton
- Android 代码中动态为RadioGroup添加RadioButton
- Dialog中存在radiogroup动态添加radiobutton的ID问题
- RadioGroup动态添加RadioButton,并且获得事件
- RadioGroup动态添加RadioButton,并且获得事件
- RadioGroup动态添加RadioButton,并且获得事件
- Android中RadioGroup在代码中动态添加子控件RadioButton
- 动态布局中RadioGroup的RadioButton有时候不互斥的原因
- 自定义RadioGroup动态添加RadioButton,并获取选中radioButton的位置
- 动态在RadioGroup加载RadioButton
- 在RadioGroup动态添加RadioButton,在构造方法里添加style。
- android 动态添加组件(RadioGroup 添加RadioButton和其他组件的一些问题)
- RadioGroup 中 RadioButton 单击事件
- 修改RadioGroup中RadioButton样式
- 动态添加RadioGroup组件的RadioButton出现多选状况解决
- PocketSphinx语音识别系统的编译、安装和使用
- cocos2dx --- 按钮点击居中放大
- POJ 1504 Adding Reversed Numbers
- Java构造方法的作用
- Android Studio开发JNI工程
- RadioGroup中动态添加RadioButton
- C语言动态规划(10)___Doing Homework(HDU 1074)
- 线程与内存
- ios开发,javascript直接调用oc代码而非通过改变url回调方式
- SVN常用命令
- spark之map与flatMap区别
- 《C++程序设计原理与实践》部分习题答案 4
- Ubuntu 12.04 LTS(64bit) 环境下JDK、 Eclipse、 ADT、 快捷图标
- 厚积薄发SEO优化干货系列–定向优化