动态改变android组件的长度

来源:互联网 发布:联友椅业 知乎 编辑:程序博客网 时间:2024/06/07 00:11
// 将dp转换为px
public static int dip2px(Context context, float dpValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}
private void addRangeWidth(LinearLayout parentLinear) {
ImageView img = null;
for (int i = 1; i <= parentLinear.getChildCount(); i++) {
img = (ImageView) parentLinear.getChildAt(parentLinear
.getChildCount() - i);
LayoutParams params = (LayoutParams) img.getLayoutParams();
params.width = dip2px(getApplicationContext(), 15 + 4 * i);
params.height = dip2px(getApplicationContext(), 12);
img.setLayoutParams(params);
img.setScaleType(ImageView.ScaleType.FIT_XY);
}
}
0 0
原创粉丝点击