简体   繁体   English

我想在Android上旋转动画imageview

[英]I want rotate animation imageview on android

i want to animate imageview on android, i want to achieve like below animation, please let me guide if any one have idea how to achieve this animation. 我想在Android上制作imageview的动画,我想实现以下动画,如果有人知道如何实现此动画,请让我指导。 在此处输入图片说明

1. Single Image animation ( motion / vibration ) 1.单图像动画(运动/振动)

Example: Under res folder, 示例:在res文件夹下,

Step1 : create a new folder called "anim" to store your animation resources and put this on that folder.( name animation.xml ) 步骤1:创建一个名为“ anim”的新文件夹来存储您的动画资源,并将其放在该文件夹中。(名称animation.xml)

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="100"
android:fromDegrees="-15"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:toDegrees="15" />

Step 2. And the method for animate the imageview 步骤2。以及使imageview动画化的方法

public void AnimateBell() {
    Animation shake = AnimationUtils.loadAnimation(mContext, R.anim.animation);
    ImageView imgBell= (ImageView) findViewById(R.id.imgBell);
    imgBell.setImageResource(R.mipmap.ic_notifications_active_white_48dp);
    imgBell.setAnimation(shake);
}

2. If you want animate with multiple image you can try as follows 2.如果要使用多个图像制作动画,可以尝试以下操作

Have you considered using Frame Animations? 您是否考虑过使用帧动画? https://developer.android.com/guide/topics/resources/animation-resource#Frame https://developer.android.com/guide/topics/resources/animation-resource#Frame

You can specify an xml in your anim folder that contains a frame-by-frame animation, specifing each image duration, and other settings, check it out 您可以在anim文件夹中指定一个xml,其中包含逐帧动画,指定每个图像持续时间和其他设置,然后将其检出

eAnimationDrawable animation = new AnimationDrawable();
animation.addFrame(getResources().getDrawable(R.drawable.image1), 100);
animation.addFrame(getResources().getDrawable(R.drawable.image2), 500);
animation.addFrame(getResources().getDrawable(R.drawable.image3), 300);
animation.setOneShot(false);

ImageView imageAnim =  (ImageView) findViewById(R.id.img);
imageAnim.setBackgroundDrawable(animation);

// start the animation!
animation.start()

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

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