Android ListView animation implementation method

Source: Internet
Author: User

Android ListView animation implementation method

In Android, listview is one of the most commonly used controls, but sometimes we think that the same listview looks too monotonous, so a listView animation is generated. If listview is loaded with an animation, the user experience will be better, in this article, we will share some listview animations and implementation methods,



I believe everyone is familiar with Android's Tween animation. The first four types of animation are Translate, Alpha, Rotate, and Scale. The last type of Rotate3d is Rotate3dAnimation, the constructor of this class receives parameters required for 3D Rotation, such as the rotation start and end angles, and the center of the rotation.

LayoutAnimationController can control the display of a group of controls according to the regulations. In ListView, mListView. setLayoutAnimation is believed to be used by everyone. The following code is used.

Private Button button, button2, button3, button4, button5; private ListView mListView; private Animation animation; private LayoutAnimationController; private String [] arry = {"1", "2 ", "3", "4", "5", "6"}; private ArrayAdapter
 
  
Adapter; protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); initView (); adapter = new ArrayAdapter
  
   
(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; display the order // LayoutAnimationController. ORDER_REVERSE; reverse display // LayoutAnimationController. ORDER_RANDOM; switch (arg0.getId () {case R. id. btn_tran: animation = new TranslateAnimation (-50f, 0f, 0f); animation. setDuration (500); // 1f is the latency controller = new LayoutAnimationController (animation, 1f); controller. setOrder (LayoutAnimationController. ORDER_NORMAL); mListView. setLayoutAnimation (controller); adapter. yydatasetinvalidated (); break; case R. id. btn_alpha: animation = new AlphaAnimation (0f, 1f); animation. setDuration (500); controller = new LayoutAnimationController (animation, 1f); controller. setOrder (LayoutAnimationController. ORDER_NORMAL); mListView. setLayoutAnimation (controller); adapter. yydatasetinvalidated (); break; case R. id. btn_rotate: animation = new RotateAnimation (0f, 360f); animation. setDuration (500); controller = new LayoutAnimationController (animation, 1f); controller. setOrder (LayoutAnimationController. ORDER_NORMAL); mListView. setLayoutAnimation (controller); adapter. yydatasetinvalidated (); break; case R. id. btn_scale: animation = new ScaleAnimation (0.1f, 1.0f, 0.1f, 1.0f); animation. setDuration (500); controller = new LayoutAnimationController (animation, 1f); controller. setOrder (LayoutAnimationController. ORDER_NORMAL); mListView. setLayoutAnimation (controller); adapter. yydatasetinvalidated (); break; case R. id. rotate3d: animation = new Rotate3dAnimation (0,360,200,200, 0, true); animation. setDuration (1000); controller = new LayoutAnimationController (animation, 0.1f); controller. setOrder (LayoutAnimationController. ORDER_NORMAL); mListView. setLayoutAnimation (controller); adapter. yydatasetinvalidated (); break; default: break ;}}
  
 

In this way, you can write your favorite animation effects as you like.


Project source code


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.