I have written an app that can drag an image and then spring back the image. But the speed of spring back is too fast. I have tried but can’t find a way to slow down it.
How can I control the speed of this?
public class CustomViewActivity extends Activity {
float mx,my;
ImageView switcherView;
Bitmap bitmap;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_view);
switcherView = (ImageView) this.findViewById(R.id.img);
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.kh06);
switcherView.setImageBitmap(bitmap);
switcherView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent event) {
float curX, curY;
//System.out.println(switcherView.getScrollX()+"--------view axis-----");
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mx = event.getX();
break;
case MotionEvent.ACTION_MOVE:
curX = event.getX();
switcherView.scrollBy((int) (mx - curX), 0);
mx = curX;
break;
case MotionEvent.ACTION_UP:
switcherView.scrollTo(0, 0);
break;
}
return true;
}
});
}
}
scaleType of image is the center,the image hasn’t been zoomed.
You need to write some code here
Instead of directly moving back to 0,0 put a for loop and go to 0,0 from current position in many iteration. some thing like this.
Update
This is code is working if you drag from right to left but when drag from left to right not working properly so correct it your self.