程序实现LayoutAnimationController

程序实现LayoutAnimationController

在res/anim下新建anim_set.xml:

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">

<alpha

android:fromAlpha="1.0"

android:toAlpha="0.0"

android:duration="3000" />

<scale

android:fromXScale="1.0"

android:toXScale="0.0"

android:fromYScale="1.0"

android:toYScale="0.0"

android:pivotX="50%"

android:pivotY="50%"

android:startOffset="100"

android:repeatCount="3"

android:duration="3000" />

</set>

在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"

android:background="#3399ff">

<ListView

android:id="@+id/myListView"

android:layout_marginLeft="8dp"

android:background="#3399ff"

android:layout_gravity="center_vertical"

android:layout_width="fill_parent"

android:layout_height="wrap_content"/>

</LinearLayout>

在布局文件info.xml中:

<?xml version="1.0" encoding="utf-8"?>

<TableLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="#3399ff">

<TableRow >

<TextView

android:id="@+id/id"

android:layout_marginLeft="8dp"

android:layout_width="100dp"

android:layout_height="30dp"/>

<TextView

android:id="@+id/title"

android:layout_width="200dp"

android:layout_height="30dp"/>

</TableRow>

</TableLayout>

在MyAnimationDemo.java中:

package com.li.animation;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import android.app.Activity;

import android.os.Bundle;

import android.view.animation.Animation;

import android.view.animation.AnimationUtils;

import android.view.animation.LayoutAnimationController;

import android.widget.GridView;

import android.widget.ListView;

import android.widget.SimpleAdapter;

public class MyAnimationDemo extends Activity {

private ListView myListView = null;

private String idData[] = new String[]{"java","android","c","c++"};

private String tileData[] = new String[]{"中国","广 西","北 海","李叶文"};

private SimpleAdapter simple = null;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

super.setContentView(R.layout.main);

this.myListView = (ListView) super.findViewById(R.id.myListView) ;

List<Map<String,Object>> all = new ArrayList<Map<String,Object>>();

Map<String,Object> map = null;

for(int x = 0; x < this.idData.length; x++){

map = new HashMap<String, Object>();

map.put("id",this.idData[x]);

map.put("title",this.tileData[x]);

all.add(map);

}

this.simple = new SimpleAdapter(this,all,R.layout.info,new String[]{

"id","data"},new int[]{R.id.id,R.id.title});

this.myListView.setAdapter(this.simple);

Animation anim = AnimationUtils.loadAnimation(this,R.anim.anim_set);

LayoutAnimationController control = new LayoutAnimationController(anim);

control.setDelay(0.5f);

control.setOrder(LayoutAnimationController.ORDER_RANDOM);

this.myListView.setLayoutAnimation(control);

}

}

上一篇:iOS开发——UI进阶篇(四)tableView的全局刷新,局部刷新,左滑操作,左滑出现更多按钮,进入编辑模式,批量删除,自定义批量删除


下一篇:IOS第七天(6:UiTableView编辑模式, 拖动位置 ,滑动删除)