English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

A Brief Discussion on the Properties and Usage of View Animation in Android

Introduction

Android animations mainly include view animations and property animations, view animations include Tween animation and Frame animation, and Tween animation includes fade animation, move animation, scale animation, and rotation animation.

Basic properties of Tween animation

      Target View;

      Duration duration;

      Start state fromXXX;

      End animation toXXX;

      Start time startOffset;

      Repeat times repeatCount;

      Timeline interpolator(interpolator).

Code Example

xml implementation

<?xml version="1.0" encoding="utf-8"?> 
<translate xmlns:android="http://schemas.android.com/apk/res/android"
 android:fromXDelta="0"
 android:fromYDelta="0"
 android:toXDelta="100%"
 android:toYDelta="0"
 android:fillAfter="true"
 android:duration="3000">
</translate>

Call in the code

Animation translate = AnimationUtils.loadAnimation(context, R.anim.translate);
imageView.startAnimation(translate);

Supplement:

1For scaling and rotation animations, there is a pivotX or pivotY that represents the center point of scaling or rotation.

There are three ways to write the corresponding attribute value.

     · Value 50 indicates the top-left corner of the current control plus50px;

     Percentage 50% represents the current control's50%;

     Percentage p 50%p represents the parent control's50%.

2In an animation collection, multiple animations can be run in parallel and sequentially by setting the stratOffset attribute.

Frame animation

The configuration file of Frame animation is placed in the drawable directory

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:drawable="@drawable/image1" android:duration="50"/>
 <item android:drawable="@drawable/image2" android:duration="50"/>
 <item android:drawable="@drawable/image3" android:duration="50"/>
</animation-list>
// It needs to be set as the background first
imageView.setBackgroundResource(R.drawable.frame_anim);
AnimationDrawable frameAnimation = (AnimationDrawable) imageView.getBackground();
frameAnimation.start();

Summary

That's all for this article. I hope the content of this article can help everyone in developing Android. If you have any questions, you can leave messages for communication.

Declaration: The content of this article is from the Internet, the copyright belongs to the original author, the content is contributed and uploaded by Internet users spontaneously, this website does not own the copyright, has not been manually edited, and does not assume relevant legal liability. If you find any content suspected of copyright infringement, please send an email to notice#w3Please report any violations by email to codebox.com (replace # with @) and provide relevant evidence. Once verified, this site will immediately delete the infringing content.

You May Also Like