Francisco Durdin Garcia
Francisco Durdin Garcia

Reputation: 13327

How to horizontal/Vertical scroll a panoramic image in Android?

I'm looking for to some way for make a scroll, or scan of a panoramic image in Android. With this I mean show a part of my image adjusting the height of the image (or width in vertical) and automatically moving slowly the view scrolling all the image. For example:

enter image description here

this image its so big to try to see it in a 16:9 device(with a bit of detail i mean), so i want to do something like:

enter image description here

Just show that part in the screen and move it slowly to the right till the end of the image. Achieving a "scroll" effect across the image.

I have been looking in the website and internet last days and I just found the library of PanoramicGL or some ways to watch 360º images.

Upvotes: 3

Views: 1858

Answers (2)

Francisco Durdin Garcia
Francisco Durdin Garcia

Reputation: 13327

Thanks to kishu, I made my own method to animate a panoramic image dynamically depending if its in landscape or portrait mode.

You can ignore the orientation value of the method, I only use it to change the animation of the video from X to Y if I want to see the image in landscape.

 public void animatePanorama(int orientation) {

    int duration;
    // The milisecons that we will use dinamically for the animation, been this is 1,31milisecons for pixel
    float miliseconsPixel = 1.31f;
    float imageWidth;

    //Delta X and Y values for the animation
    float deltaX = 0f;
    float deltaY = 0f;
    float aspectRatio;
    //We get the drawable from the container to calcule his real Width and Height
    final Drawable d = mImageContainer.getDrawable();
    final int origWidth = d.getIntrinsicWidth();
    final int origHeight = d.getIntrinsicHeight();
    //With that we get the real aspect ratio and a duration

    if (origWidth > origHeight) {
        aspectRatio = (float) origWidth / (float) origHeight;
        duration = (int) (miliseconsPixel * origWidth);
        imageWidth = mImageContainer.getMeasuredHeight() * aspectRatio;
    } else {
        aspectRatio = (float) origHeight / (float) origWidth;
        duration = (int) (miliseconsPixel * origHeight);
        imageWidth = mImageContainer.getMeasuredWidth() * aspectRatio;
    }

    //Set if the animation will be horizontal(Portrait) or Vertical(landscape)
    if (orientation == 0 || orientation == 180)
        deltaX = imageWidth / 2f - mImageContainer.getMeasuredWidth() / 2;
    else
        deltaY = imageWidth / 2f - mImageContainer.getMeasuredHeight() / 2;

    //New Animation
    Animation animation = new TranslateAnimation(deltaX, -deltaX, deltaY, -deltaY);
    //Add Duration
    animation.setDuration(duration);
    animation.setFillAfter(true);
    //Add cycle for repeating mode
    animation.setRepeatCount(-1);
    animation.setRepeatMode(Animation.REVERSE);
    mImageContainer.startAnimation(animation);
}

Upvotes: 0

Nandkishor mewara
Nandkishor mewara

Reputation: 2562

This Is For Scroll Click Here

You must use PanoramaClient (which is part of Google Play Services) to open PhotoSphere photos.

An example of how to do this can be found on this Android developer blog post:

// This listener will be called with information about the given panorama.
OnPanoramaInfoLoadedListener infoLoadedListener =
new OnPanoramaInfoLoadedListener() {
@Override
public void onPanoramaInfoLoaded(ConnectionResult result,
                                 Intent viewerIntent) {
    if (result.isSuccess()) {
        // If the intent is not null, the image can be shown as a
        // panorama.
        if (viewerIntent != null) {
            // Use the given intent to start the panorama viewer.
            startActivity(viewerIntent);
        }
    }

    // If viewerIntent is null, the image is not a viewable panorama.
 }
 };
 // Create client instance and connect to it.
 PanoramaClient client = ...
 ...
 // Once connected to the client, initiate the asynchronous check on whether
 //the image is a viewable panorama.
 client.loadPanoramaInfo(infoLoadedListener, panoramaUri);

Upvotes: 1

Related Questions