I have a layout, which include two ImageViews. I want to create an easy way to include pinch zoom on ImageViews. I have watched some codes, but they work only on single ImageView. Is it possible to make this work on a layout with ImageViews?
Asked
Active
Viewed 2,280 times
1 Answers
0
Write Below Code for Drag two image into your Activity File and implement pinch zoom code into this.
windowwidth = getWindowManager().getDefaultDisplay().getWidth();
windowheight = getWindowManager().getDefaultDisplay().getHeight();
tv1 = (ImageView)findViewById(R.id.image);
tv1.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
layoutParams1 = (RelativeLayout.LayoutParams) tv1.getLayoutParams();
switch(event.getActionMasked())
{
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
int x_cord = (int) event.getRawX();
int y_cord = (int) event.getRawY();
if (x_cord > windowwidth) {
x_cord = windowwidth;
}
if (y_cord > windowheight) {
y_cord = windowheight;
}
layoutParams1.leftMargin = x_cord - 25;
layoutParams1.topMargin = y_cord - 75;
tv1.setLayoutParams(layoutParams1);
break;
default:
break;
}
return true;
}
});
tv2 = (ImageView)findViewById(R.id.image1);
tv2.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
layoutParams2 = (RelativeLayout.LayoutParams) tv2.getLayoutParams();
switch(event.getActionMasked())
{
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
int x_cord = (int) event.getRawX();
int y_cord = (int) event.getRawY();
if (x_cord > windowwidth) {
x_cord = windowwidth;
}
if (y_cord > windowheight) {
y_cord = windowheight;
}
layoutParams2.leftMargin = x_cord - 25;
layoutParams2.topMargin = y_cord - 75;
tv2.setLayoutParams(layoutParams2);
break;
default:
break;
}
return true;
}
});
XML File:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:layout_width="50sp" android:layout_height="50sp"
android:id="@+id/image" android:src="@drawable/image">
</ImageView>
<ImageView android:layout_y="30dip" android:layout_x="118dip"
android:layout_width="50sp" android:layout_height="50sp" android:id="@+id/image1"
android:src="@drawable/image1">
</ImageView>
</RelativeLayout>
And see below link for more information.

Community
- 1
- 1

Dipak Keshariya
- 22,193
- 18
- 76
- 128
-
i have implemented this code http://stackoverflow.com/questions/10630373/android-image-view-pinch-zooming its not working for me....do u have any code pls help – user960439 Dec 08 '12 at 05:26
-
@user960439 Do you have working pinch zoom code for one image? – Dipak Keshariya Dec 08 '12 at 05:28
-
@user960439 If possible post your full code in your question. – Dipak Keshariya Dec 08 '12 at 05:48
-
here is that code http://www.codeproject.com/Articles/319401/Simple-Gestures-on-Android – user960439 Dec 08 '12 at 05:59
-
let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/20787/discussion-between-user960439-and-dipak-keshariya) – user960439 Dec 08 '12 at 06:03