Android ApiDemos example resolution (127): Views-& gt; Layout Animation-& am

Source: Internet
Author: User

In this example, we use TranslateAnimation to show down the Animation effect of a list item (Cascade) of a ListView. For details about the basic Animation, see Android ApiDemos example resolution (3 ): app-> Activity-> Animation.

In this example, the code is used to add LayoutAnimation to the ListView.

[Java]
AnimationSet set = new AnimationSet (true );
 
Animation animation = new AlphaAnimation (0.0f, 1.0f );
Animation. setDuration (50 );
Set. addAnimation (animation );
 
Animation = new TranslateAnimation (
Animation. RELATIVE_TO_SELF, 0.0f,
Animation. RELATIVE_TO_SELF, 0.0f,
Animation. RELATIVE_TO_SELF,-1.0f,
Animation. RELATIVE_TO_SELF, 0.0f
);
Animation. setDuration (2000 );
Set. addAnimation (animation );
 
LayoutAnimationController controller
= New LayoutAnimationController (set, 0.5f );
ListView listView = getListView ();
ListView. setLayoutAnimation (controller );

AnimationSet set = new AnimationSet (true );

Animation animation = new AlphaAnimation (0.0f, 1.0f );
Animation. setDuration (50 );
Set. addAnimation (animation );

Animation = new TranslateAnimation (
Animation. RELATIVE_TO_SELF, 0.0f,
Animation. RELATIVE_TO_SELF, 0.0f,
Animation. RELATIVE_TO_SELF,-1.0f,
Animation. RELATIVE_TO_SELF, 0.0f
);
Animation. setDuration (2000 );
Set. addAnimation (animation );

LayoutAnimationController controller
= New LayoutAnimationController (set, 0.5f );
ListView listView = getListView ();
ListView. setLayoutAnimation (controller );
In this example, the Cascade effect is implemented through TranslateAnimation. The constructor used in this example is as follows:

Public TranslateAnimation (int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue)

FromXType: Specifies the fromXValue mode. In this example, RELATIVE_TO_SELF is used to indicate the width or height of the View. RELATIVE_TO_PARENT is the width or height of the parent View. ABSOLUTE indicates that fromXValue uses ABSOLUTE values.
FromXValue: The coefficient relative to the current View or parent View when fromXType is RELATIVE_TO_PARENT or RELATIVE_TO_SELF. In this example, expand downward and there is no animation in the X direction, so it is set to 0.
ToXType: Specifies the toXValue mode. In this example, RELATIVE_TO_SELF is used to indicate the width or height of the View. RELATIVE_TO_PARENT is the width or height of the parent View. ABSOLUTE indicates that fromXValue uses ABSOLUTE values.
ToXValue: The coefficient relative to the current View or parent View when fromXType is RELATIVE_TO_PARENT or RELATIVE_TO_SELF. In this example, expand downward and there is no animation in the X direction, so it is set to 0.
FromYType: Specifies the fromYValue mode. In this example, RELATIVE_TO_SELF is used to indicate the width or height of the View. RELATIVE_TO_PARENT is the width or height of the parent View. ABSOLUTE indicates that fromYValue uses ABSOLUTE values.
FromYValue: The coefficient relative to the current View or parent View when fromYType is RELATIVE_TO_PARENT or RELATIVE_TO_SELF.
ToYType: indicates the toYValue mode. In this example, RELATIVE_TO_SELF is used to indicate the width or height of the View. RELATIVE_TO_PARENT is the width or height of the parent View. ABSOLUTE indicates that fromXValue uses ABSOLUTE values.
ToYValue: The coefficient relative to the current View or parent View when fromYType is RELATIVE_TO_PARENT or RELATIVE_TO_SELF. In this example, expand down. A value of 1 indicates moving down the height of the sub-View.
Changing the animation time from 100 to 2000 can display the animation effect at a slower speed.

 
 


 

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.