现在的位置: 首页 > 综合 > 正文

程序实现LayoutAnimationController

2018年03月31日 ⁄ 综合 ⁄ 共 3121字 ⁄ 字号 评论关闭

 

 

在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);

  }

}

 

【上篇】
【下篇】

抱歉!评论已关闭.