i'm very new to Android SDK, so excuse my silly question. I made a simple app with an ImageView set as background android:background="@drawable/image" and i added two zoom buttons, so i can zoom in and out the picture that is on the whole screen.So my question is should i use OnTouchListener or is there a better way to just move the picture view up,down, left or right with my finger, i just need these basic events, nothing else. I'm added part of my code, if anyone advises me, where would be better to implement it.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_load_map);
zoom = (ZoomControls) findViewById(R.id.zoomControls1);
img = (ImageView) findViewById(R.id.imageView1);
startX = img.getScaleX();
startY = img.getScaleY();
zoom.setOnZoomInClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
float x = img.getScaleX();
float y = img.getScaleY();
img.setScaleX((float) (x+1));
img.setScaleY((float) (y+1));
}
});
zoom.setOnZoomOutClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
float x = img.getScaleX();
float y = img.getScaleY();
if((x>startX) & (y>startY)) {
img.setScaleX((float) (x-1));
img.setScaleY((float) (y-1));
}
}
});
}
Is it best to use OnTouchListener ?
Yes this is a good way to implement the movement of OnTouchListener for ImageView.
you can go through here
https://developer.android.com/training/gestures/multi.html
http://www.techotopia.com/index.php/Android_Touch_and_Multi-touch_Event_Handling
http://www.mysecretroom.com/www/programming-and-software/android-multi-touch-handling
http://judepereira.com/blog/multi-touch-in-android-translate-scale-and-rotate/
http://examples.javacodegeeks.com/android/core/ui/listview/android-multitouch-listview-example/
http://android-developers.blogspot.in/2010/06/making-sense-of-multitouch.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.