Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6074547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:23:40+00:00 2026-05-23T10:23:40+00:00

i am new to android and was trying to implement swipe effects on images

  • 0

i am new to android and was trying to implement swipe effects on images loaded from url in an imageview…and i succeeded but now i want more than one url should be loaded and i can able to see them all one by one by swiping finger on the device screen as a single image covering the whole screen…
i tried very much bt fails to implement..
i dont know more than one image view will be used….some for loop & array or what!!!
just helpless b’coz attempted more than 30 times…

pls somebody help….thanx in advance……

this is my code:

package com.conn;

import android.R;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.ViewFlipper;

public class swipe_touch extends Activity {
    private static final String LOGID = "CHECKTHISOUT";

    private static final int SWIPE_MIN_DISTANCE = 120;
    private static final int SWIPE_MAX_OFF_PATH = 250;
    private static final int SWIPE_THRESHOLD_VELOCITY = 200;
    private GestureDetector gestureDetector;
    View.OnTouchListener gestureListener;

    private Animation slideLeftIn;
    private Animation slideLeftOut;
    private Animation slideRightIn;
    private Animation slideRightOut;
    private ViewFlipper viewFlipper;

    String message = "Initial Message"; 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.main);
      //Set up viewflipper
        viewFlipper = new ViewFlipper(this);  

        ImageView[] img = new ImageView[i];
        j_comm_func funs = new j_comm_func();//already made this class
        BitmapFactory.Options bmOptions;
        bmOptions = new BitmapFactory.Options();
        bmOptions.inSampleSize = 1;
        Bitmap bm = funs.LoadImage("http://65.175.77.34/newsnow/2462011/largest3/2462011-md-hr-1.jpg", bmOptions);
        img.setImageBitmap(bm);


        viewFlipper.addView(img);



        //set up animations
        slideLeftIn = AnimationUtils.loadAnimation(this, R.anim.slide_out_right);
        slideLeftOut = AnimationUtils.loadAnimation(this, R.anim.slide_in_left);
        slideRightIn = AnimationUtils.loadAnimation(this, R.anim.slide_in_left);
        slideRightOut = AnimationUtils.loadAnimation(this, R.anim.slide_out_right);


        //put up a brownie as a starter
        setContentView(viewFlipper);

        gestureDetector = new GestureDetector(new MyGestureDetector());
    }

    public class MyGestureDetector extends SimpleOnGestureListener {
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            try {
                if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
                    return false;
                // right to left swipe
                if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                    Log.v(LOGID,"right to left swipe detected");
                    viewFlipper.setInAnimation(slideLeftIn);
                    viewFlipper.setOutAnimation(slideLeftOut);
                    viewFlipper.showNext();
                    setContentView(viewFlipper);

                } // left to right swipe 
                else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                    Log.v(LOGID,"left to right swipe detected");                    
                    viewFlipper.setInAnimation(slideRightIn);
                    viewFlipper.setOutAnimation(slideRightOut);
                    viewFlipper.showPrevious();
                    setContentView(viewFlipper);

                }
            } catch (Exception e) {
                // nothing
            }
            return false;
        }
    }

    // This doesn't work
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (gestureDetector.onTouchEvent(event)){
            Log.v(LOGID,"screen touched");
            return true;
        }
        else{
            return false;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:23:40+00:00Added an answer on May 23, 2026 at 10:23 am

    Well… your method onTouchEvent doesnt work because all touch events are consumed by ViewFlipper (from docs to this activity’s method:

    Called when a touch screen event was not handled by any of the views under it. This is most useful to process touch events that happen outside of your window bounds, where there is no view to receive it.
    )

    To implement the thing you want take a look here: Android touch events with multiple views(such as a ListView in a Viewflliper)

    In your case you should do something like this:

    img.setOnTouchListener(new DragableViewTouchListener());
    

    To add zoom features you can do many things…I advise you to do the following:

    1. Create the extension of ImageView: ZoomableImageVIew
    2. Override the method dispatchTouchEvent like this:

      public boolean dispatchTouchEvent(MotionEvent event) {
      if(needZoom(event)) {
         doZoom();
         // the event was handled. Do not propagate it to prevent handling it in ViewFlipper.
         return true;
      } else {
         // propagate the event (to ViewFlipper)
         super.dispatchTouchEvent(event);
      }
      

      }

    Good luck !!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement swipe in android from left to right and right
I'm trying to implement a MediaPlayer on an Android app, but now I have
i'm trying to implement action bar in 2.3.3 version. As i'm new to android
I am new to Android's MapView. I am trying to implement event listeners that
I'm trying to implement async on Android but it keeps crashing my app, the
I am trying to implement date picker on a button in android. But as
I am trying to implement Camera application in android,and i got some code from
I am new to Android and trying to implement the sample AlarmController application. Everything
I'm trying to record audio this.recorder = new android.media.MediaRecorder(); this.recorder.setAudioSource(android.media.MediaRecorder.AudioSource.MIC); this.recorder.setOutputFormat(android.media.MediaRecorder.OutputFormat.DEFAULT); this.recorder.setAudioEncoder(android.media.MediaRecorder.AudioEncoder.DEFAULT); this.recorder.setOutputFile(pruebaAudioRecorder.mp4); **this.recorder.prepare();**
I'm new to Android and I think I'm trying to do something really basic:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.