[英]Move ImageView around inside RelativeLayout
I need to move an ImageView (or anything else, for that matter) around inside a RelativeLayout. 我需要在RelativeLayout内部移动ImageView(或其他任何东西)。 Does any one know the proper way to do this?
有没有人知道这样做的正确方法?
Makesure ImageView 's layout_height and layout_width is set to fill_parent . Menseure ImageView的layout_height和layout_width设置为fill_parent 。 Then do:
然后做:
To move a view, use Matrix . 要移动视图,请使用Matrix 。 It is very handy.
这非常方便。
Matrix matrix = new Matrix();
matrix.reset();
matrix.postTranslate(x, y);
imageview.setScaleType(ScaleType.MATRIX);
imageview.setImageMatrix(matrix);
我找到了这个:
imageview.layout(l,t,r,b);
mImageView.scrollBy(xOffset,yOffset);
It is very easy. 这很容易。 You can implement
onTouchListener
event of any control you want and set its x, y position like make a new LayoutParams
set its x, y and assign to view as view.setLayoutParam(layoutParams);
你可以实现你想要的任何控件的
onTouchListener
事件,并设置它的x,y位置,比如make一个新的LayoutParams
设置它的x,y并分配给view.setLayoutParam(layoutParams);
it will drag the View. 它将拖动视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.