开发者

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

开发者 https://www.devze.com 2023-04-03 11:56 出处:网络
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.

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

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

If you have noticed, the image seems left the previous state during dragging. Any inputs are appre开发者_Go百科ciated.


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.


Call invalidate in ondraw method.


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号