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(gestureHintImage, gestureParam);