ImageView lockImage = new ImageView(mContext); // 设置当前图像的图像 lockImage.setPadding(20, 20, 20, 20); //设置padding 属性 RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE); lp.rightMargin = 27; lp.topMargin = 20; lockImage.setLayoutParams(lp); //设置layout 属性 this.addView(lockImage); //将imageview 添加到layout中
转载于:https://my.oschina.net/farina/blog/753236