listView——animation xml方式输出实现动画效果

效果图

 

 

一、activity代码

package com.liudan.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class ListViewAnimation extends Activity {
   
 private ListView listView;
 private Button button;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        listView = (ListView)findViewById(R.id.listView);
        button = (Button)findViewById(R.id.button);
        button.setOnClickListener(new ButtonListener());
    }
    private ListAdapter buildListAdapter(){
     List<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
     HashMap<String,String> mhashMap1 = new HashMap<String,String>();
     mhashMap1.put("userName", "张三");
     mhashMap1.put("userGender", "男");
     HashMap<String,String> mhashMap2= new HashMap<String,String>();
     mhashMap2.put("userName", "张三");
     mhashMap2.put("userGender", "男");
     HashMap<String,String> mhashMap3 = new HashMap<String,String>();
     mhashMap3.put("userName", "张三");
     mhashMap3.put("userGender", "男");
     list.add(mhashMap1);
     list.add(mhashMap2);
     list.add(mhashMap3);
     SimpleAdapter simpleAdapter = new SimpleAdapter(this,list
       ,R.layout.item,new String[] {"userName","userGender"},
       new int[] {R.id.userName,R.id.userGender});
     
     return simpleAdapter;
    }
    private class ButtonListener implements OnClickListener{

  @Override
  public void onClick(View v) {
   listView.setAdapter(buildListAdapter());
   
  }
     
    }
}

二、xml代码

在res下新建list_anim_layout.xml 和 list_anim.xml  

 

<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"

 android:delay="0.5"
 android:animationOrder="random"
 android:animation="@anim/list_anim"
 />
<!--
间隔时间是0.5秒,顺序是random随机
 -->

 

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
 android:interpolator="@android:anim/accelerate_interpolator">
<alpha
 android:fromAlpha="0.0"
 android:toAlpha="1.0"
 android:duration="2000"
 />

</set>

 

main.xml  和 item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<ListView
 android:id="@+id/listView" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layoutAnimation="@anim/list_anim_layout"
    />
    <Button
 android:id="@+id/button" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="测试动画输出listView"
    />
</LinearLayout>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
 android:id="@+id/userName" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    />
    <TextView
 android:id="@+id/userGender" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    />
</LinearLayout>

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值