android动态添加组件,在项目中会经常使用到,首先罗列一下是我自己遇到的一些问题及解决办法
一、 曾经遇到一个问题解决了好久,(RadioGroup 添加RadioButton和其他组件),当RadioGroup动态添加非RadioButton时有时该组件的宽度会默认为wrapcontent,即使你使用了matchparent。
此时我们可以把宽度设为定值,避免其自动wrap

RadioGroup rg = new RadioGroup(getContext());rg.setOrientation(LinearLayout.VERTICAL);//垂直方向ViewGroup.LayoutParams rg_lp = new ViewGroup.LayoutParams(600, RadioGroup.LayoutParams.WRAP_CONTENT);//rg的宽度设值为600,确定的值rg.setLayoutParams(rg_lp);LinearLayout.LayoutParams lp_et = new LinearLayout.LayoutParams(600, 100);//et的长宽设置final EditText et = new EditText(getContext());et2.setLayoutParams(lp_et2);rg.addView(rb);rg.addView(et);

此时,edittext的长度将为600个像素,长度可控,不再自适应。

更多相关文章

  1. Android架构组件(Architecture Components)介绍
  2. android webview里设置cookie
  3. ImageView的属性 android:scaleType
  4. 一步一步学android之布局管理器——FrameLayout
  5. Android(安卓)TextUtil
  6. Android的shape的使用
  7. Android5.0 材质设计(纸墨设计)中的z轴理念
  8. Android(安卓)View - 实现流式布局
  9. 文本类控件(EditView 的介绍)

随机推荐

  1. Android系统Choreographer机制实现过程
  2. [Innost]Android深入浅出之Binder机制
  3. json解析查找指定数据字段
  4. android 微博客户端源码
  5. android 调用call
  6. Android Studio 使用Gradle在Terminal终
  7. Android -- Dialog动画
  8. Android(安卓)Path里FillType功能
  9. Android延时任务方法
  10. android Intent打开各种类型文件((PDF、wo