scale animation

Scale animation: You use this type of animation to make a view smaller
or larger either on the x axis or on the y axis. You can also specify the
pivot point around which you want the animation to take place.

下面我们将要实现一个scale Animation的小列子


1)在anim文件夹下用xml定义一个scale Animation

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<scale
android:fromXScale="1"
android:toXScale="1"
android:fromYScale="0.1"
android:toYScale="1.0"
android:duration="500"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="100" />
</set>

2)define the main.xml    其中listView 中的每一个item将会按照scale Animation中
定义好的方式展示出来
 
<?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:id="@+id/list_view_id"
  android:persistentDrawingCache="animation|scrolling"
  android:layout_width="fill_parent" android:layout_height="fill_parent"
  android:layoutAnimation="@anim/list_layout_controller" />
 />
</LinearLayout>

注意到这里有一个android:layoutAnimation 属性
the ListView requires another XML file that acts as a mediator between itself and the animation set.
the mediator 就是上面的list_layout_controller, 用xml文件中实现, 下面是实现的代码

<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:delay="30%"
android:animationOrder="reverse"
android:animation="@anim/scale" />

这样一来就可以将listview中的item按照定义好的scale Animation展示
出来了

这是Activity的代码
package hust.ophoneclub.ScaleAnimation;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ScaleAnimation extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setupLiatView();
    }

 /**
  *
  */
 private void setupLiatView() {
  String[] listItems = new String[]{
    "Item1", "Item2", "Item3",
    "Item4", "Item5", "Item6"
  };
  ArrayAdapter listItemAdapter =
   new ArrayAdapter(this, android.R.layout.simple_list_item_1,
     listItems);
  ListView listView = (ListView)findViewById(R.id.list_view_id);
  listView.setAdapter(listItemAdapter);
 }
}scale animation

效果是每个item中的文字会沿着y轴扩展开来

你可能感兴趣的:(android,xml,OS)