zoukankan      html  css  js  c++  java
  • 程序实现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);

      }

    }

  • 相关阅读:
    指针、数组和结构体的一些思考
    Leetcode589.N-ary Tree Preorder TraversalN叉树的前序遍历
    Leetcode563.Binary Tree Tilt二叉树的坡度
    Leetcode559.Maximum Depth of N-ary TreeN叉树的最大深度
    Leetcode561.Array Partition I数组拆分1
    Leetcode551.Student Attendance Record I学生出勤记录1
    Leetcode543.Diameter of Binary Tree二叉树的直径
    Leetcode520Detect Capital检测大写字母
    Leetcode532.K-diff Pairs in an Array数组中的K-diff数对
    Leetcode496.Next Greater Element I下一个更大的元素1
  • 原文地址:https://www.cnblogs.com/riskyer/p/3317977.html
Copyright © 2011-2022 走看看