Android ListView Animation Implementation Method

Source: Internet
Author: User

In Android, the ListView is one of the most commonly used controls, but sometimes we feel that the stereotyped ListView looks too monotonous, so it produces a ListView animation, and the ListView loads the animation to make the user experience better. This issue to share some of the ListView animations and implementation methods,



I believe everyone is familiar with Android tween animation, the first four kinds of animation is Translate,alpha,rotate,scale, the last Rotate3d is a 3D rotary animation tool class rotate3danimation, The constructor of this class receives some of the parameters that are needed for 3D rotation, such as the angle at which the rotation starts and ends, the center point of the rotation, and so on.

Layoutanimationcontroller can control a set of controls to show, Mlistview.setlayoutanimation in the ListView believe everyone knows what to do, and then the code

Private button button, Button2, Button3, Button4, button5;private ListView mlistview;private Animation animation;private Layoutanimationcontroller controller;private string[] Arry = {"One", "two", "three", "four", "five", "Six"};p rivate Arrayadapter<stri ng> adapter;protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Initview (); adapter = new Arrayadapter<string> (this,android. R.layout.simple_list_item_1, Arry); Mlistview.setadapter (adapter);} private void Initview () {//TODO auto-generated method Stubmlistview = (ListView) Findviewbyid (r.id.list); button = (button ) Findviewbyid (R.id.btn_tran); Button.setonclicklistener (this); button2 = (Button) Findviewbyid (R.id.btn_alpha); Button2.setonclicklistener (this), Button3 = (Button) Findviewbyid (r.id.btn_rotate); Button3.setonclicklistener (this ); button4 = (Button) Findviewbyid (R.id.btn_scale); Button4.setonclicklistener (this); button5 = (Button) Findviewbyid ( R.id.rotate3d); button5.seTonclicklistener (this);} @Overridepublic void OnClick (View arg0) {//Layoutanimationcontroller.order_normal; sequential Display// Layoutanimationcontroller.order_reverse; anti-display//layoutanimationcontroller.order_random; Randomly displayed switch (Arg0.getid ()) {Case r.id.btn_tran:animation = new Translateanimation ( -50f, 0f, 0f, 0f); Animation.setduration,//1F is the delay controller = new Layoutanimationcontroller (animation, 1f); Controller.setorder ( Layoutanimationcontroller.order_normal); mlistview.setlayoutanimation (Controller); Adapter.notifydatasetinvalidated (); Break;case r.id.btn_alpha:animation = new Alphaanimation (0f, 1f); Animation.setduration, controller = new Layoutanimationcontroller (animation, 1f); Controller.setorder ( Layoutanimationcontroller.order_normal); mlistview.setlayoutanimation (Controller); Adapter.notifydatasetinvalidated (); Break;case r.id.btn_rotate:animation = new Rotateanimation (0f, 360f); Animation.setduration, controller = new Layoutanimationcontroller (animation, 1f); Controller.setorder ( LayoutanimatIoncontroller.order_normal); mlistview.setlayoutanimation (Controller); adapter.notifydatasetinvalidated (); break; Case r.id.btn_scale:animation = new Scaleanimation (0.1f, 1.0f, 0.1f, 1.0f); animation.setduration; controller = new Layoutanimationcontroller (animation, 1f); Controller.setorder (Layoutanimationcontroller.order_normal); Mlistview.setlayoutanimation (Controller); adapter.notifydatasetinvalidated (); Break;case r.id.rotate3d:animation = New Rotate3danimation (0, 0, true); Animation.setduration (+); controller = new Layoutanimationcontroller (animation, 0.1f); Controller.setorder (Layoutanimationcontroller.order_normal); Mlistview.setlayoutanimation ( Controller); adapter.notifydatasetinvalidated (); break;default:break;}}

So you can write your favorite animations as you like.


Project Source


Android ListView Animation Implementation Method

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.