您的位置:首页 > 移动开发 > Android开发

动态的添加ImageView并居中显示

2017-09-07 14:25 501 查看
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 控件 imageview
相关文章推荐