vrpanorama上图像之间的平滑过渡(无缝)

时间:2018-11-01 11:40:51

标签: android android-animation google-vr

我要根据时间长度在vrpanorama视图中显示一组图像。时间到时,image1将更改为image2。但是我想使图像从image1过渡到image2变得平滑或无缝。我在过渡期间应用了Alpha动画,但显示不流畅。谁能帮我解决代码中的问题?

ublic class MainActivity extends AppCompatActivity {

private VrPanoramaView mVRPanoramaView;
public int counter=0;




@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mVRPanoramaView = (VrPanoramaView) findViewById(R.id.vrPanoramaView);

    AssetManager assetManager=getAssets(); // to reach asset
    try {
        final String[] images = assetManager.list("img");// to get all item in img folder.
        animate(mVRPanoramaView, images,false);

    }catch (IOException e) {
        e.printStackTrace();
    }



}



private void animate(final VrPanoramaView imageView, final String images[], final boolean forever) {

    //imageView <-- The View which displays the images
    //images[] <-- Holds R references to the images to display
    //imageIndex <-- index of the first image to show in images[]
    //forever <-- If equals true then after the last image it starts all over again with the first image resulting in an infinite loop. You have been warned.

    int fadeInDuration = 2000; // Configure time values here //1000 millisecond= 1 second
    int timeBetween = 3000;
    int fadeOutDuration =2000;




    //imageView.setVisibility(View.INVISIBLE);    //Visible or invisible by default - this will apply when the animation ends
    //imageView.setImageResource(images[imageIndex]);
    VrPanoramaView.Options options = new VrPanoramaView.Options();
    options.inputType = VrPanoramaView.Options.TYPE_MONO;

    InputStream inputStream = null;



    try {
        inputStream = getAssets().open("img/" + images[counter]);

    }catch (IOException e) {
        e.printStackTrace();
    }






    Animation fadeIn = new AlphaAnimation(0f,1f); // 0 ,1 (fromAlpha, toAlpha)
    fadeIn.setInterpolator(new DecelerateInterpolator()); // add this
    fadeIn.setDuration(fadeInDuration);


    Animation fadeOut = new AlphaAnimation(1f,0f); //1,0
    fadeOut.setInterpolator(new AccelerateInterpolator(10000)); // and this
    fadeOut.setStartOffset(fadeInDuration + timeBetween);
    fadeOut.setDuration(fadeOutDuration);

    AnimationSet animation = new AnimationSet(true); // change to false
    animation.addAnimation(fadeIn);
    animation.addAnimation(fadeOut);
    animation.setRepeatCount(0);
    imageView.setAnimation(animation);

    imageView.loadImageFromBitmap(BitmapFactory.decodeStream(inputStream), options);


    animation.setAnimationListener(new Animation.AnimationListener() {
        public void onAnimationEnd(Animation animation) {
            if (images.length > counter) {
                animate(imageView, images,forever); //Calls itself until it gets to the end of the array
                counter++;
            }
            else {

                    counter=0;
                    animate(imageView, images,forever);  //Calls itself to start the animation all over again in a loop if forever = true
            }
        }
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub
        }
        public void onAnimationStart(Animation animation) {
            // TODO Auto-generated method stub


        }
    });
}







@Override
protected void onPause() {
    super.onPause();
    mVRPanoramaView.pauseRendering();

}

@Override
protected void onResume() {
    super.onResume();
    mVRPanoramaView.resumeRendering();

}

@Override
protected void onDestroy() {
    mVRPanoramaView.shutdown();
    super.onDestroy();

}

}

0 个答案:

没有答案