Android开发:在布局里移动ImageView控件

时间:2023-03-09 08:48:06
Android开发:在布局里移动ImageView控件

在做一个app时碰到需要移动一个图案的位置,查了一上午资料都没找到demo,自己写一个吧

 RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT); lp.setMargins(left, top, right, bottom);
xImageView.setLayoutParams(lp);

习惯了在xml文件中写死margins属性,现在需要动态修改布局就没辙了。。

若不需要设置与某边距的距离,置0就可以了,xImageView是控件的名称。