如何 horizontal/Vertical 在 Android 中滚动全景图像?

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

我正在寻找在 Android 中制作滚动或扫描全景图像的方法。我的意思是显示我的图像的一部分,调整图像的高度(或垂直宽度)并自动缓慢移动视图滚动所有图像。例如:

这张图片太大了,可以尝试在 16:9 设备中查看它(我的意思是有一点细节),所以我想做类似的事情:

只需在屏幕上显示该部分,然后将其慢慢向右移动,直到图像结束。实现整个图像的 "scroll" 效果。

我最近几天一直在网站和互联网上查找,我刚刚找到了 PanoramicGL 库或一些观看 360º 图像的方法。

这是为了 滚动 Click Here

您必须使用 PanoramaClient(它是 Google Play Services) to open PhotoSphere 照片的一部分。

可以在这个 Android 开发者博客 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);

感谢 kishu,我创建了自己的方法来根据全景图像是横向模式还是纵向模式动态地设置全景图像的动画。

你可以忽略该方法的方向值,如果我想横向查看图像,我只用它来将视频的动画从 X 更改为 Y。

 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);
}