小编Kam*_*mal的帖子

拖动多个图像不起作用

我正在开发一个使用拖放图像的应用程序我可以在相对布局中添加任意数量的图像.我能够拖动图像,但一次只能拖动一个.一旦我添加新图像,所有以前的图像都不可触摸.

public void addImage(Bitmap bmp)
{
    ivtest= new ImageView(TabletActivity.this);
    if(bmp!=null)
    {
        ivtest.setImageBitmap(bmp);
        rlAddView.addView(ivtest,  new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

        bmp= null;
    }
    ivtest.setTag("sdjfjd");
    ivtest.bringToFront();
    ivtest.setScaleType(ScaleType.MATRIX);
    ivtest.setOnTouchListener(this);
}
Run Code Online (Sandbox Code Playgroud)

这是我添加新图像的代码.ivtest是一个全局imageView.

public class TestImage extends View  implements OnTouchListener
{
private ScaleGestureDetector mScaleDetector;
private float mScaleFactor = 1.f;
private Drawable mIcon;
private float mLastTouchX;
private static final int INVALID_POINTER_ID = -1;

// The ‘active pointer’ is the one currently moving our object.
private int mActivePointerId = INVALID_POINTER_ID;
 private float mPosX;
    private float mPosY;

    private float mLastTouchY;


public …
Run Code Online (Sandbox Code Playgroud)

android

6
推荐指数
1
解决办法
2734
查看次数

标签 统计

android ×1