移动和缩放多个图像单个活动上的视图



我能够在单个图像上实现拖动和缩放视图,从这里这里也是代码;

public class Touch extends Activity {
private static final String TAG = "Touch";
Matrix matrix = new Matrix();
Matrix savedMatrix = new Matrix();
private PointF start = new PointF();
private PointF mid = new PointF();
private float oldDist = 1f;
// We can be in one of these 3 states
static final int NONE = 0;
static final int DRAG = 1;
static final int ZOOM = 2;
int mode = NONE;
ImageView tv1;
LayoutParams layoutParams1;
ImageView tv2;
LayoutParams layoutParams2;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final int windowwidth = getWindowManager().getDefaultDisplay()
            .getWidth();
    final int windowheight = getWindowManager().getDefaultDisplay()
            .getHeight();
    tv1 = (ImageView) findViewById(R.id.imageView);
    tv1.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            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.imageView2);
    tv2.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            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:

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
    android:id="@+id/imageView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scaleType="matrix"
    android:src="@drawable/ic_launcher" />
    </LinearLayout>

现在我的问题是我想动态添加多个图像视图并应用拖动,缩放每个图像视图。谁能帮助我实现这一目标?我见过许多其他方法,但都有一些限制。

在此

示例中,您可以将图像拖动为图库视图并能够进行捏合缩放。 在此示例中,您有一个适配器类..,因此您可以动态绑定图像。

以这种方式绑定...

for(int i=0;i<bmpList.size();i++)
            {
                ImageViewTouch imageView = new ImageViewTouch(Philately_image_view.this);
                imageView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
                Options options = new Options();
                options.inSampleSize = 2;
                //Bitmap bitmap = BitmapFactory.decodeFile(file.getPath(), options);
                imageView.setImageBitmap(bmpList.get(i));
                arrayAdapter.add(imageView);

            }
            galleryTouch.setAdapter(arrayAdapter);

在这里我有位图的数组列表...和图库触摸图库触摸对象..

最新更新