Android property animation-property animation (6)

Source: Internet
Author: User

Animations for layout changes of viewgroups objects

The property animation system provides an easy way to process the animation changes of viewgroup objects as well as view objects.

Layouttransition class is used to process layout changes in viewgroup. When you call the setvisibility () method of a view object, set the gone constant of the view, or add the view object to the viewgroup (or delete it from the viewgroup, the view object inside the viewgroup can achieve the animation effect of the current time. When a view object is added or deleted in a viewgroup object, other view objects can be animated to a new position. In the layouttransition object, you can define the animation represented by the constant by calling the setanimator () method and passing the following layouttransition constant to the animator object parameter of the method:

1. Appearing --- a tag that indicates that an animation is to be run on the displayed project in the container;

2. Change appearing --- a tag that indicates the animation to be run for changes to other projects in the container due to the appearance of a new project;

3. Disappearing --- a tag that indicates the animation to be run for a project that disappears from the container;

4. change_disappearing --- a tag that indicates the animation to be run because a project disappears from the container and changes other projects.

You can define custom animations for these four event types to customize the layout transition effect. You can also tell the animation system to only use the default animation effect.

The layoutanimations example in apidemo shows how to define the animation effect for the layout transition and set the animation on the view object for the animation effect.

The layoutanimationsbydefault class and its corresponding layout_animations_by_default.xml layout resource file show how to enable the default layout transition effect of viewgroup objects in XML. You only need to set the Android. animatelayoutchanges attribute of the viewgroup element to true. For example:

<Linearlayout

Android: Orientation = "vertical"

Android: layout_width = "wrap_content"

Android: layout_height = "match_parent"

Android: Id = "@ + ID/verticalcontainer"

Android: animatelayoutchanges = "true"/>

If this attribute is set to true, you can add or delete a view object to or from the viewgroup object, and other view objects in the viewgroup object will be automatically animated.

Use typeevaluator

If the animation type you want is unknown to the Android system, you can create your own evaluators by implementing the typeevaluator interface. The available types of Android systems are int, float, or color, which are supported by evaluators of the intevaluator, floatevaluator, and argbevaluator types.

There is only one method to implement in the typeevaluator interface: The evaluate () method. This method allows an animation processor in use to return an animation attribute value suitable for the current animation time point. The floatevaluator class demonstrates how this method works:

Public class floatevaluator implements typeevaluator {

Public object evaluate (float fraction, object startvalue, object endvalue ){

Float startfloat = (number) startvalue). floatvalue ();

Return startfloat + fraction * (number) endvalue). floatvalue ()-startfloat );

}

}

Note: When the valueanimator object (or objectanimator object) is running, it calculates the current animation playback ratio (a value between 0 and 1 ), calculate the version of the animation to be inserted based on the interpolation type you use. The interpolation ratio is received by the typeevaluator object through the fraction parameter. Therefore, interpolation is not required when calculating the animation value.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.