ImageView 在移动后,调用setBackground会使移动失效的解决方法

来源:互联网 发布:深入解析wpf编程 pdf 编辑:程序博客网 时间:2024/06/05 05:00

在项目中,需要在自定义的ImageView中的onTouchEvent设置背景,导致移动失效,回到原来的位置。

查找资料后,发现在设置背景前面,使用setLayoutParams方法可以解决。



代码:

this.setLayoutParams(new AbsoluteLayout.LayoutParams((int)(this.getWidth()),(int)(this.getHeight()),this.getLeft(),this.getTop()));
this.setBackground(getResources().getDrawable(R.drawable.square_green_border));

0 0
原创粉丝点击