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

在ListView上使用动画

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

 

 

 

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

 

 

 

 

在res/anim下新建layout_animation.xml:

 

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

<layoutAnimation

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

  android:delay="0.5"

  android:animationOrder="random"

  android:animation="@anim/anim_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"

     android:layoutAnimation="@anim/layout_animation"/>

</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.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);

  }

}

 

抱歉!评论已关闭.