Animation使用方法(二)

本文介绍了一种使用Android动画实现列表项渐显效果的方法。通过自定义动画控制器,实现了列表视图中每一项以淡入的形式出现。该教程适用于Android开发者学习动画效果的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

效果图同:Animation使用方法(一)的效果图
工程结构图:
[img]
[img]http://dl.iteye.com/upload/attachment/617390/6bce39dc-fea9-3c9f-ab1c-d87cd2ac3b85.png[/img]
[/img]

可以看到,比Animation使用方法(一)的工程结构少了一个:list_controller.xml
布局文件的
main.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:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@id/android:list"
/>
</LinearLayout>


user.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:padding="10dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/name"
android:layout_width="180dp"
android:layout_height="30dp"
android:layout_marginLeft="20dp"
android:textColor="#fff"
android:textSize="10pt"
android:singleLine="true"
/>
<TextView
android:id="@+id/age"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
android:textColor="#fff"
android:gravity="right"
android:textSize="10pt"
/>
</LinearLayout>


/res/anim/alpha.xml
<?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"
></alpha>
</set>


AnimationDemo4Activity
package 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{

@Override
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub

}

}

}


本文转自:http://theron.blog.51cto.com/2383825/656690
只可用于学习。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值