在ImageView中翻转和更改图像 [英] Flipping and changing image in ImageView

查看:456
本文介绍了在ImageView中翻转和更改图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款工作简单且运行效率很高的应用程序.但是我有一个地方,我看的东西看起来不太好,这会翻转动画.

I am working on a App that is simple in work and it is working quite efficiently. But I have one place where I am looking something is not looking great and that is flipping Animation.

我想要的是:

我有一个按钮和一个位于按钮下方的Im​​ageView.在一个按钮上,单击我要制作一个动画,它看起来像ImageView已翻转,并且下一个图像显示在ImageView中".因此,每次单击时,它应显示带有翻转动画的下一幅图像,但是存在一些问题.稍后再讨论,但首先让我向您展示我的操作方式.

I have a Button and a ImageView beneath the button. On a Button click I want to make a Animation that it looks like ImageView has flipped and next image is shown in the ImageView. So on every click it should show next image with a flipping animation but there are some problems. I would discuss later but first let me show you how I am doing this.

到目前为止我做了什么:

What I have done so far :

flipping.xml

flipping.xml

<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
    android:valueFrom="0" android:valueTo="180" android:propertyName="rotationY" >
</objectAnimator>

活动中

@Override
public void onClick(View v) {
     flipAnimation();
     ivAnimPicture.setImageResource(myImage1);      
}

private void flipAnimation(){
    ObjectAnimator anim = (ObjectAnimator) AnimatorInflater.loadAnimator(this, R.animator.flipping);
    anim.setTarget(ivAnimPicture);
    anim.setDuration(1500);
    anim.start();
}

问题

当它从0旋转到180时,恰好在90度时,我们可以看到图像视图边缘,因此它使动画看起来不太好.并且还首先更改图像,然后启动Flipping动画,在我希望该Flipping动画应该开始的位置,并在其中出现新图像.因此,当动画停止播放时,应该会为用户提供令人惊讶的新图像. 因此,我真的不希望在图像视图中设置图像",然后启动动画"并对图像视图进行动画处理

When It rotates to 180 from 0 , when it comes exactly at 90 degree we can see image view edges so it makes the animation look not so good. and Also the image changes first then the Flipping animation starts where as I want that Flipping animation should start and in the middle of it the new image should appear. so when the animation stops there should be surprisingly new image for the user. So I really do not want Image to set in the image-view and then the Animation starts and Animate the image view

请向我建议一种更好的方法,或者是否有一些尚未淘汰的图书馆.

Please suggest me more good way or if there is library which is not obsolete.

推荐答案

Chathuranga的解决方案可以完成这项工作.但是你更好:

Chathuranga's solution will do the job. but you better:

1.使用ViewPropertyAnimator.特别是,当您需要在多个ImageViews上执行不同的动画时.

1.Use ViewPropertyAnimator. Specially, when you need to perform different animations on several ImageViews.

2.从270f旋转到360f进行第二次翻转,否则您的图像将被镜像.

2.rotate from 270f to 360f for second flip, otherwise your image will be mirrored.

3.将第二张图片加载到Drawable 开始之前,以进行平滑旋转.

3.Load your second Image into a Drawable before starting the animation, to have a smooth rotation.

final Drawable drawable=getResources().getDrawable(R.drawable.a);
final ImageView iv = ((ImageView)findViewById(R.id.imageView1));
iv.setRotationY(0f);
iv.animate().rotationY(90f).setListener(new AnimatorListener() 
            {

                @Override
                public void onAnimationStart(Animator animation) 
                {
                }

                @Override
                public void onAnimationRepeat(Animator animation) 
                {                       
                }

                @Override
                public void onAnimationEnd(Animator animation) 
                {   
                    iv.setImageDrawable(drawable);
                    iv.setRotationY(270f);
                    iv.animate().rotationY(360f).setListener(null);

                }

                @Override
                public void onAnimationCancel(Animator animation) 
                {                       
                }
            });

这篇关于在ImageView中翻转和更改图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆