java android中的卡片翻转动画

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46111262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 09:04:02  来源:igfitidea点击:

Card flip animation in android

javaandroidxml

提问by POUYA KARIMI

I have tired to make a flip card in android.Please make an image view,when I click on,it flip like  this

我已经厌倦了在android中制作翻转卡。请制作图像视图,当我点击时,它会翻转  这

回答by Cahid Enes Kele?

imageView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        final ObjectAnimator oa1 = ObjectAnimator.ofFloat(imageView, "scaleX", 1f, 0f);
        final ObjectAnimator oa2 = ObjectAnimator.ofFloat(imageView, "scaleX", 0f, 1f);
        oa1.setInterpolator(new DecelerateInterpolator());
        oa2.setInterpolator(new AccelerateDecelerateInterpolator());
        oa1.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                imageView.setImageResource(R.drawable.frontSide);
                oa2.start();
            }
        });
        oa1.start();
    }
});

This animation doesn't have any depth but maybe you will like it.

这个动画没有任何深度,但也许你会喜欢它。

You can also set animation duration with

您还可以设置动画持续时间

oa1.setDuration(1000);
oa2.setDuration(1000);

回答by bwt

Property Animations(not to be confused with the older View Animation) are quite powerful :

属性动画(不要与旧的视图动画混淆)非常强大:

final View v = <the_image_view>;

// first quarter turn
v.animate().withLayer()
        .rotationY(90)
        .setDuration(300)
        .withEndAction(
                new Runnable() {
                    @Override public void run() {

                        <change the image...>

                        // second quarter turn
                        v.setRotationY(-90);
                        v.animate().withLayer()
                                .rotationY(0)
                                .setDuration(300)
                                .start();
                    }
                }
        ).start();

You can adjust the perspective effect with View.setCameraDistance()

您可以使用View.setCameraDistance()调整透视效果