Amandeep singh
Amandeep singh

Reputation: 1883

how to move images on finger touch in android?

I am developing an small application in a android. Before this i had done surfing on internet but i can't get useful material. In this application i have two tabs I had made the these two tabs but I want after click on first tab i want some images these Images can move on right side when user touch it on right and left side when user touch it left means user can slide the images on both left and right by finger. Can anyone suggest me any tutorial or source code so that i can able to do functionality like this.

Thanks in advance

Upvotes: 1

Views: 11306

Answers (2)

Amitabha
Amitabha

Reputation: 1662

int x1 = (int) event.getX();       
int y1 = (int) event.getY();

imageobject.layout(x1,x1+(width_of_imageobject),y1,y1+(width_of_imageobject));

Upvotes: 0

wheaties
wheaties

Reputation: 35970

See this blog post on how to do it. You need to look at SurfaceView and the onTouchListener. Taken from the blog:

              surf.setOnTouchListener( new SurfaceView.OnTouchListener(){
                  public boolean onTouch(View v, MotionEvent event) {
                     case MotionEvent.ACTION_MOVE:
                        if( moving ){
                            final int x_new = (int)event.getX();
                            final int y_new = (int)event.getY();
                            mDrawTiles.draw( new DrawLogic(){
                                @Override
                                public void draw(Rect _surface) {
                                    mTiles.setBounds(
                                        x_new - mDrawWidth/2,
                                        y_new - mDrawHeight/2,
                                        x_new + mDrawWidth/2,
                                        y_new + mDrawHeight/2);
                                    }
                                });
                            }

Upvotes: 3

Related Questions