0

I have two images in a framelayout. i want to be able to touch the screen and slide the top image to the left reveling the second image. I tried to do this by using ontouch listener. I cant seem to get it working. The first image stretches. any help? Im trying to achieve something like the yahoo weather app, like how you can switch cities in the app. I have the second image offset to the right and when i scroll i have to move the top image and lower the offset of the second image so it becomes centered.

  layout = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,FrameLayout.LayoutParams.MATCH_PARENT);


      Im2.setOnTouchListener(new OnTouchListener()
   {
       int prevX,prevY;
      int y=0;
       @Override
       public boolean onTouch(final View v,final MotionEvent event)

       {


       switch(event.getAction())
         {

         case MotionEvent.ACTION_UP:
           {
               v.setLayoutParams(layout);





           return true;
           }
         case MotionEvent.ACTION_MOVE:
         {



            layout.leftMargin+=(int)event.getRawX()-prevX;
            Log.d(" MAIN  ", "  Y value " + event.getX());
            layout.rightMargin= (int) (-(0.10)*(int)event.getRawX()-prevX);
            prevX=(int)event.getRawX();


       v.setLayoutParams(layout);
       ///fam.setLayoutParams(layout);


             return true;
         }




         case MotionEvent.ACTION_DOWN:
           {

               prevX=(int)event.getRawX();
               v.setLayoutParams(layout);

           return true;

           }
         }
       return true;
       }
     });
Samantha
  • 199
  • 5
  • 15

2 Answers2

0

Use a viewpager instead of a framelayout.

JoxTraex
  • 13,423
  • 6
  • 32
  • 45
0

It's better to try using a ViewFlipper or a ViewPager for screen slides.

Jade Byfield
  • 4,668
  • 5
  • 30
  • 41