Java动态设置ImageView的setPadding无效,解决办法

在Java中动态生成ImageView时,用setPadding(left, top, right, bottom);没有效果

ImageView img = new ImageView(Scdzyx.this);

img.setPadding(left, top, right, bottom);


解决办法:

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 1);

params.setMargins(15, 10, 0, 10);

img.setLayoutParams(params);

你可能感兴趣的:(java,Android)