• 一起学android之设置ListView数据显示的动画效果(24)


    效果图:



    平时我们要实现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<String> arrayAdapter = new ArrayAdapter<String>(
    				MainActivity.this, android.R.layout.simple_list_item_1,
    				str_name);
    		// 绑定适配器
    		lv_arrayadapter.setAdapter(arrayAdapter);
    	}
    
    }
    


    activity_main.xml:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
       >
    
        <ListView  
            android:id="@+id/lv_arrayadapter"  
            android:layout_width="fill_parent"  
            android:layout_height="wrap_content" >  
        </ListView>  
    
    </RelativeLayout>



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

  • 相关阅读:
    配置Yaf
    计算机科学中最重要的32个算法
    mysql show status详解
    Structs 在Struts.xml中配置action时,action的name属性最好首字母大写
    MyEclipse创建ssh项目和连接数据库
    Myeclipse安装svn插件
    win7安装ubuntu双系统
    Java查看API和源码的方法
    华为oj平台的新网址
    详细解析Java中抽象类和接口的区别
  • 原文地址:https://www.cnblogs.com/blfbuaa/p/7289954.html
Copyright © 2020-2023  润新知