首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

Animation使用方法(1)

2012-08-13 
Animation使用方法(一)这里要使用到LayoutAnimationController。这个类可以用在一个布局文件中的layout内,

Animation使用方法(一)
这里要使用到LayoutAnimationController。这个类可以用在一个布局文件中的layout内,对该layout内部的控件进行控制,也可以用在Java代码中,实现同样的效果。
效果图:三个item逐个显现。
[img]

[/img]
工程结构图:
[img]

[/img]

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"android:layoutAnimation="@anim/list_controller"/></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"><alphaandroid:fromAlpha="0.0"android:toAlpha="1.0"android:duration="2000"></alpha></set>

/res/anim/list_controller.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/alpha"/>


AnimationDemo3Activity
package cxt.demo;import java.util.ArrayList;import java.util.HashMap;import android.app.ListActivity;import android.os.Bundle;import android.widget.SimpleAdapter;public class AnimationDemo3Activity extends ListActivity {private ArrayList<HashMap<String,Object>> list = null;    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);                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);    }        }


本文转自:http://theron.blog.51cto.com/2383825/656690
只可用做学习。

热点排行