Animation使用方法(二)
效果图同:Animation使用方法(一)的效果图
工程结构图:
[img]
[/img]
可以看到,比Animation使用方法(一)的工程结构少了一个:list_controller.xml
布局文件的
main.xml
user.xml
/res/anim/alpha.xml
AnimationDemo4Activitypackage cxt.demo;import java.util.ArrayList;import java.util.HashMap;import android.app.ListActivity;import android.os.Bundle;import android.view.animation.Animation;import android.view.animation.AnimationUtils;import android.view.animation.LayoutAnimationController;import android.view.animation.Animation.AnimationListener;import android.widget.ListView;import android.widget.SimpleAdapter;public class AnimationDemo4Activity extends ListActivity {private ArrayList<HashMap<String,Object>> list = null;private ListView listView = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); listView = getListView(); list = new ArrayList<HashMap<String,Object>>(); HashMap<String,Object> m1 = new HashMap<String, Object>(); HashMap<String,Object> m2 = new HashMap<String, Object>(); HashMap<String,Object> m3 = new HashMap<String, Object>(); m1.put("image", R.drawable.z11); m1.put("name", "Jack"); m1.put("age","63"); m2.put("image", R.drawable.z22); m2.put("name", "Bob"); m2.put("age","15"); m3.put("image", R.drawable.z33); m3.put("name", "Theron"); m3.put("age","25"); list.add(m1); list.add(m2); list.add(m3); SimpleAdapter adapter = new SimpleAdapter(this, list, R.layout.user, new String[]{"image","name","age"}, new int[]{R.id.image,R.id.name,R.id.age}); setListAdapter(adapter); Animation animation = AnimationUtils.loadAnimation(AnimationDemo4Activity.this, R.anim.alpha); LayoutAnimationController controller = new LayoutAnimationController(animation); controller.setOrder(LayoutAnimationController.ORDER_NORMAL); listView.setLayoutAnimation(controller); } private class AnimationImpl implements AnimationListener{@Overridepublic void onAnimationEnd(Animation arg0) {// TODO Auto-generated method stub}@Overridepublic void onAnimationRepeat(Animation arg0) {// TODO Auto-generated method stub}@Overridepublic void onAnimationStart(Animation arg0) {// TODO Auto-generated method stub} } }
本文转自:http://theron.blog.51cto.com/2383825/656690
只可用于学习。