动态的添加ImageView并居中显示
16lz
2021-01-23
Android 中动态添加控件,并设置居中和Margin:
其中DisplayUtil.dip2px()是为了适配。
SimpleDraweeView image = new SimpleDraweeView(getContext()); LayoutParams param = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); param.height = DisplayUtil.dip2px(getContext(), 140); param.width = DisplayUtil.dip2px(getContext(), 140); param.setMargins(0, DisplayUtil.dip2px(getContext(), 200), 0, 0); // Margin param.addRule(RelativeLayout.CENTER_HORIZONTAL);//水平居中 addView(image, param);
更多相关文章
- Android Studio学习:简单控件:Button控件的点击、长按函数重写
- 水平布局linerlayout
- android的一些自定义控件
- android : 控件在代码中设置属性-setWidth(int pixels)或setHeig
- android之4.0控件switch自定义开关背景图片和控制宽度
- 控件布局_TableLayout
- Android 日历方式显示的日期选择组件(日历控件之一)
- 控件的圆角