简体   繁体   English

如何在Android中将动画应用于imageview?

[英]How to apply a animation to an imageview in android?

what i am trying to do here is,i have downloaded some images in my application and i want to show these images one by one to the user in full screen after some times say every 30 seconds.I also applied an animation to the imageview when image changes here is my code:- 我要在这里做的是,我已经在应用程序中下载了一些图像,我想在每隔30秒说完几遍后向用户全屏显示这些图像。图像更改是我的代码:-

protected Bitmap doInBackground(String... params) {
    // TODO Auto-generated method stub
    if (!isCancelled()) 
    {

    filename=params[0];
   if(ShowImages.vn>d2)
   {
    ShowImages.vn=0;   
   }
    bmp = BitmapFactory.decodeFile(filename);
    }
    return bmp;

}
protected void onPostExecute(Bitmap result) {
        // TODO Auto-generated method stub
    super.onPostExecute(result);
    ShowImages.tt1.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
         r1 = AnimationUtils.loadAnimation(ShowImages.context, R.anim.lefttoright);
        ShowImages.tt1.setImageBitmap(result);
        ShowImages.tt1.startAnimation(r1);
    }

    }

this is my code for my animation file: 这是我的动画文件代码:

<set xmlns:android="http://schemas.android.com/apk/res/android"
 android:shareInterpolator="false">
  <translate android:fromXDelta="-100%" android:toXDelta="0%"
           android:fromYDelta="0%" android:toYDelta="0%"
            android:duration="700"/>
       </set>

i have no problem with this code it is executing fine,but when the image change takes place the whole imageview goes blank for some time and then the next image comes.I do not want this,i want the previous image to be there untill the next image change has taken place,can someone suggest me a method for this. 我对此代码没有问题,它可以很好地执行,但是当发生图像更改时,整个图像视图在一段时间内变为空白,然后出现下一个图像。我不希望这样,我希望以前的图像在那里,直到下一个图片发生了变化,有人可以建议我这样做的方法。

In your case it would be good to use frame-by-frame animation as well define on developer site Frame- by- frame: An object used to create frame-by-frame animations, defined by a series of Drawable objects, which can be used as a View object's background. 在您的情况下,最好使用逐帧动画以及在开发人员网站上定义逐帧动画 :逐帧:用于创建逐帧动画的对象,该对象由一系列Drawable对象定义,可以是用作View对象的背景。

Check below tutorial even you will get more example, just try to Google: 即使您将获得更多示例,也请查看以下教程,只需尝试使用Google:

Displaying a frame-by-frame animation in Android 在Android中显示逐帧动画

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM