Android Animation---实现ListView项一行一行逐渐显示效果

需要实现的效果参见题目,直接参见Demo:

AnimationsActivity.java

package com.example.androidlistanimationdemo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.ListActivity;
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 AnimationsActivity extends ListActivity {
    private Button button = null;
    private ListView listView = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animations);
        listView = getListView();
        button = (Button)findViewById(R.id.button);
        button.setOnClickListener(new ButtonListener());
    }
    private ListAdapter createListAdapter() {
        List<HashMap<String,String>> list = 
            new ArrayList<HashMap<String,String>>();
        HashMap<String,String> m1 = new HashMap<String,String>();
        m1.put("name", "bauble");
        m1.put("sex", "male");
        HashMap<String,String> m2 = new HashMap<String,String>();
        m2.put("name", "Allorry");
        m2.put("sex", "male");
        HashMap<String,String> m3 = new HashMap<String,String>();
        m3.put("name", "Allotory");
        m3.put("sex", "male");
        HashMap<String,String> m4 = new HashMap<String,String>();
        m4.put("name", "boolbe");
        m4.put("sex", "male");
        list.add(m1);
        list.add(m2);
        list.add(m3);
        list.add(m4);
        SimpleAdapter simpleAdapter = new SimpleAdapter(
                this,list,R.layout.item,new String[]{"name","sex"},
                new int[]{R.id.name,R.id.sex});
        return simpleAdapter;
    }
    private class ButtonListener implements OnClickListener{
        public void onClick(View v) {
            listView.setAdapter(createListAdapter());
        }
    }
} 

 

新建资源anim文件夹:

list_anim_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:delay="0.5"
    android:animationOrder="normal"
    android:animation="@anim/list_anim"/>

list_anim.xml

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

 

ListView自定义布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:orientation="horizontal" 
    android:paddingLeft="10dip"
    android:paddingRight="10dip" 
    android:paddingTop="1dip"
    android:paddingBottom="1dip">
    <TextView android:id="@+id/name" 
        android:layout_width="180dip"
        android:layout_height="30dip" 
        android:textSize="5pt"
        android:singleLine="true" />
    <TextView android:id="@+id/sex" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:textSize="5pt" 
        android:singleLine="true"/>
</LinearLayout> 

APP主题布局文件:

<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/android:list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"
        android:layoutAnimation="@anim/list_anim_layout"/>
    <Button 
        android:id="@+id/button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="测试"/>
</LinearLayout>

 

注意关键字layoutAnimation

这个是对整体布局内部(布局内部所有UI元素---这个非常重要)的元素UI一个一个的显示效果出来.

 

demo下载:http://pan.baidu.com/s/1bnhIPcV

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值