Android 中動(dòng)態(tài)添加控件,并設(shè)置居中和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);