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 );}}
Activity_main.xml:
Reprinted please indicate the source: http://blog.csdn.net/hai_qing_xu_kong/article/details/44248637 sentiment control _