Learn how to set the animation effect of ListView data display for android

Source: Internet
Author: User

Learn how to set the animation effect of ListView data display for android



To achieve the animation effect when displaying ListView data, you can use LayoutAnimationController to set the animation effect for ListView, set it using the setLayoutAnimation method of ListView, and then startLayoutAnimation to start the animation. See the following code:


Public class MainActivity extends Activity {private ListView lv_arrayadapter; private String [] str_name = new String [] {"jack", "debb", "robin", "kikt ", "dog", "cat", "elep"}; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); initView (); setData (); loadAnimation ();} private void loadAnimation () {/** create an animation set */AnimationSet set = new AnimationSet (false ); animation animation;/** create a rotation animation */animation = new RotateAnimation (180, 10); Animation. setduration( 1000); set. addAnimation (animation); LayoutAnimationController controller = new LayoutAnimationController (set, 1); controller. setInterpolator (this, android. r. anim. accelerate_interpolator); controller. setAnimation (set); lv_arrayadapter.setLayoutAnimation (controller); lv_arrayadapter.startLayoutAnimation ();} private void initView () {lv_arrayadapter = (ListView) findViewById (R. id. lv_arrayadapter); // registers the listener event lv_arrayadapter.setOnItemClickListener (new OnItemClickListener () {@ Overridepublic void onItemClick (AdapterView
 Parent, View view, int position, long id) {Toast. makeText (MainActivity. this, str_name [position], Toast. LENGTH_SHORT ). show () ;}}) ;}private void setData () {// create ArrayAdapterArrayAdapter
ArrayAdapter = new ArrayAdapter
(MainActivity. this, android. R. layout. simple_list_item_1, str_name); // bind the adapter lv_arrayadapter.setAdapter (arrayAdapter );}}








Reprinted please indicate the source: http://blog.csdn.net/hai_qing_xu_kong/article/details/44248637 sentiment control _

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.