Android之设置ListView数据显示的动画效果

效果图:

 

平时我们要实现ListView数据显示时的动画效果,可以使用LayoutAnimationController为ListView设置动画效果,并通过ListView的setLayoutAnimation方法来设置,最后startLayoutAnimation,启动动画。参看以下代码:

 

public class MainActivity extends Activity {
	private ListView lv_arrayadapter;
	private String[] str_name = new String[] { "jack", "debb", "robin", "kikt",  
            "dog", "cat", "elep" }; 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initView();
		setData();
		loadAnimation();
	}

	private void loadAnimation() {
		/*
		 * 创建动画的集合
		 */
		AnimationSet set = new AnimationSet(false);
		
		Animation 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);
		// 注册监听事件
		lv_arrayadapter.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView parent, View view,
					int position, long id) {
				Toast.makeText(MainActivity.this, str_name[position],
						Toast.LENGTH_SHORT).show();

			}
		});

	}

	private void setData() {
		// 创建ArrayAdapter
		ArrayAdapter arrayAdapter = new ArrayAdapter(
				MainActivity.this, android.R.layout.simple_list_item_1,
				str_name);
		// 绑定适配器
		lv_arrayadapter.setAdapter(arrayAdapter);
	}

}

 

 

activity_main.xml:

 



      
      

 

 

 

 

 

 

转载请注明出处:http://blog.csdn.net/hai_qing_xu_kong/article/details/44248637 情绪控_
 

你可能感兴趣的:(Android,Android开发笔记)