这是我正在做的非常简单的事情,我以前做过,但现在它没有像我预期的那样运行。无论如何,让我简要解释一下我正在尝试做什么以及我得到了什么::
场景::
我有一个放置RelativeLayout
了一个ImageView
,现在我设置touchlistener
如下:imageview.setOnTouchListener(this);
它要求我覆盖onTouch(View v,MotionEvent event)
我所做的函数......并且在Action_Move
我得到x和y并将它们添加到左边距和上边距,这样我正在移动我的图像。
奇怪的问题:
我ImageView
正在移动,但震动非常明显,就像我朝正确的方向移动一样,ImageView
会向右侧移动,但在途中它又回到左侧,因此看起来图像不稳定,它在振动。 . 类似的东西.. 我给出了我得到的x和y ......log
希望这能给你这个想法。
ACTION_DOWN[#0(pid 0)=160,233] Going right..
ACTION_MOVE[#0(pid 0)=160,233] ////
ACTION_MOVE[#0(pid 0)=160,233] //
ACTION_MOVE[#0(pid 0)=174,231] //
ACTION_MOVE[#0(pid 0)=176,233] //
ACTION_MOVE[#0(pid 0)=196,232] //
ACTION_MOVE[#0(pid 0)=152,232] // suddenly i got 152 as location for x... image comes back
ACTION_MOVE[#0(pid 0)=167,232] // again started to go right
ACTION_MOVE[#0(pid 0)=180,233] // going right
ACTION_MOVE[#0(pid 0)=173,233] // again comes a little back
ACTION_MOVE[#0(pid 0)=187,232] // same thing goes till end..
ACTION_MOVE[#0(pid 0)=159,232]
ACTION_MOVE[#0(pid 0)=174,231]
ACTION_MOVE[#0(pid 0)=177,233]
ACTION_MOVE[#0(pid 0)=189,231]
ACTION_MOVE[#0(pid 0)=155,232]
ACTION_MOVE[#0(pid 0)=171,231]
ACTION_MOVE[#0(pid 0)=183,230]
ACTION_MOVE[#0(pid 0)=161,234]
ACTION_MOVE[#0(pid 0)=171,233]
ACTION_MOVE[#0(pid 0)=174,230]
ACTION_MOVE[#0(pid 0)=183,230]
ACTION_MOVE[#0(pid 0)=162,234]
ACTION_MOVE[#0(pid 0)=170,233]
ACTION_MOVE[#0(pid 0)=176,233]
ACTION_MOVE[#0(pid 0)=165,233]
ACTION_MOVE[#0(pid 0)=175,232]
ACTION_MOVE[#0(pid 0)=163,233]
ACTION_MOVE[#0(pid 0)=171,233]
ACTION_MOVE[#0(pid 0)=167,233]
ACTION_MOVE[#0(pid 0)=172,232]
ACTION_MOVE[#0(pid 0)=178,232]
ACTION_MOVE[#0(pid 0)=158,234]
ACTION_MOVE[#0(pid 0)=170,234]
ACTION_MOVE[#0(pid 0)=170,232]
ACTION_MOVE[#0(pid 0)=177,231]
ACTION_MOVE[#0(pid 0)=157,234]
ACTION_MOVE[#0(pid 0)=160,234]
ACTION_MOVE[#0(pid 0)=169,232]
ACTION_MOVE[#0(pid 0)=165,233]
ACTION_MOVE[#0(pid 0)=167,233]
ACTION_MOVE[#0(pid 0)=159,233]
ACTION_UP [#0(pid 0)=161,233]
相对布局的 XML 代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#99000000">
<ImageView
android:id="@+id/imageview"
android:layout_width="400dp"
android:layout_height="400dp"
android:layout_marginLeft="100dp"
android:layout_marginTop="100dp"
android:scaleType="matrix" />
</RelativeLayout>
所以,这是最大的,我可以解释我的问题,如果你需要什么,请告诉我。
更新::ImageView
在其容器
中移动的代码,即RelativeLayout
:
case MotionEvent.ACTION_MOVE:
LayoutParams params = (LayoutParams) imageview.getLayoutParams();
params.leftMargin = params.leftMargin + x;
params.topMargin = params.topMargin + y;
imageview.setLayoutParams(params);
break;