Android: How to: implement image drag and zoom extending ImageView using multi touch capability of 2.1 up

折月煮酒 提交于 2019-12-24 07:24:53

问题


I have this kind of behavior when I drag or zoom the image.

If you have noticed, the image seems left the previous state during dragging. Any inputs are appreciated.


回答1:


Please try to build the following a project.

https://github.com/gabu/AndroidSDK-RecipeBook/tree/master/Recipe060

This project is Running fine on Nexus S/Android 2.3.4

Please compare the your code and this project.




回答2:


Call invalidate in ondraw method.




回答3:


Try this,

I have a very sucessive solution for you,i m very sure that it will work for you,

try to use TouchImageView instead of ImageView in Layout.because touchimageview have property that zooming in or out itself

https://github.com/MikeOrtiz/TouchImageView


from this link you learn how to use touchimageview...


Then After implement onDragListener of TouchImageView so you can get DRAG And Drop of Imageview easily...

    @Override
    public boolean onDrag(View v, DragEvent event) {

        switch (event.getAction()) {

            case DragEvent.ACTION_DROP:

                TouchImageView target = (TouchImageView) v;
                TouchImageView dragged = (TouchImageView) event.getLocalState();

                Drawable target_draw = target.getDrawable();
                Drawable dragged_draw = dragged.getDrawable();

                dragged.setImageDrawable(target_draw);
                target.setImageDrawable(dragged_draw);

       }
        return true;
    }

here both cases I implementing in my app,so definately solve your problem...



来源:https://stackoverflow.com/questions/7356031/android-how-to-implement-image-drag-and-zoom-extending-imageview-using-multi-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!