Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example Analysis of the realization principle of Animation in Android

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "case Analysis of the realization principle of Animation in Android". The editor shows you the operation process through the actual case. The operation method is simple, fast and practical. I hope this article "case Analysis of the realization principle of Animation in Android" can help you solve the problem.

Android Animation Classification

In Android, we generally divide animation into two categories, one is View Animation (View Animation), the other is Property Animation, of course, there are also three types, Frame Animation,Tween Animation, and Property Animation. Because the first two generally act on the whole View, they are collectively called View Animation. It is also explained in two categories in Google's official documentation.

Material Design has been added in Android 5.0.Some animations have been implemented in Material Design to provide feedback to users and provide visual continuity as they interact with your application. It will provide some default animation for button and action behavior transformations, we can customize touch feedback, use disclosure effects, customize action behavior transformations, specify custom transformations, use transformations to start an action behavior, start an action behavior with shared elements, and so on.

Frame Animation

As the implementation of Frame Animation,Tween Animation is still different, let's introduce the two methods separately. Frame Animation actually shows a series of pictures one by one, which is similar to our watching movies, because the human eye has an acceptable temporary stay, which is why people will feel stuttered when watching videos online. Of course, this is the basis for us to achieve Frame Animation. The shorter it takes to play the same number of pictures, the more smooth it will be, and the natural person will feel that it is an animation. Our common Gif is actually frame animation. If you open Gif animation with PhotoShop, you will find that there are a lot of layers in it, that is, a lot of frames.

There are two ways to implement Frame animation. The first way is to create a xml file under the drawable folder. Its syntax is very simple, as follows

You will find that the realization of Frame animation is very simple, with few attributes. Animation-list is the root element of the animation. The oneshot attribute in the root element represents the number of times the animation is executed. If set to true, it will only be played once. If false, it will be executed in a loop all the time. Under the root element, there is an item element, which is the picture we want to add. Each item represents a frame, the drawable under item is our image resource, and duration is the time when the animation of that frame is executed. For example

The method of use is as follows

/ / you can set background imageView.setBackgroundResource (R.drawable.frame_run_animation) in xml; AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground (); animationDrawable.start ()

Run the effect image as above. If we do not add the oneshot attribute above, the attribute defaults to false, that is, the animation will be executed in a loop all the time. When we set true, the animation will stop when it is played to the last frame. When we want to stop, we can use the stop method of AnimationDrawable. It also provides the isRunning () method to determine whether the animation has been executed. Another thing we need to pay attention to is to beware of OOM.

Of course, it is also very simple to implement in code, as follows

Private void addFrame () {AnimationDrawable animationDrawable = new AnimationDrawable (); int [] mipmaps = new int [] {R.mipmap.run1, R.mipmap.run2, R.mipmap.run3, R.mipmap.run4, R.mipmap.run5, R.mipmap.run6, R.mipmap.run7, R.mipmap.run8,}; for (int I = 1; I

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report