费话不多说,直接上代码


TVOffAnimation.java
package com.iaiai.activity;import android.graphics.Matrix;import android.view.animation.AccelerateDecelerateInterpolator;import android.view.animation.Animation;import android.view.animation.Transformation;/** *  * <p> * Title: TVOffAnimation.java * </p> * <p> * E-Mail: 176291935@qq.com * </p> * <p> * QQ: 176291935 * </p> * <p> * Http: iaiai.iteye.com * </p> * <p> * Create time: 2012-10-8 下午1:33:44 * </p> *  * @author 丸子 * @version 0.0.1 */public class TVOffAnimation extends Animation {private int halfWidth;private int halfHeight;@Overridepublic void initialize(int width, int height, int parentWidth, int parentHeight) {super.initialize(width, height, parentWidth, parentHeight);setDuration(500);setFillAfter(true);// 保存View的中心点halfWidth = width / 2;halfHeight = height / 2;setInterpolator(new AccelerateDecelerateInterpolator());}@Overrideprotected void applyTransformation(float interpolatedTime, Transformation t) {final Matrix matrix = t.getMatrix();if (interpolatedTime < 0.5) {matrix.preScale(1 + 0.625f * interpolatedTime, 1 - interpolatedTime / 0.8f + 0.003f, halfWidth, halfHeight);} else {matrix.preScale(7.5f * (1 - interpolatedTime), 0.003f, halfWidth, halfHeight);}}}


MainActivity.java
package com.iaiai.activity;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;/** *  * <p> * Title: MainActivity.java * </p> * <p> * E-Mail: 176291935@qq.com * </p> * <p> * QQ: 176291935 * </p> * <p> * Http: iaiai.iteye.com * </p> * <p> * Create time: 2012-10-8 下午1:33:44 * </p> *  * @author 丸子 * @version 0.0.1 */public class MainActivity extends Activity {@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);findViewById(R.id.btn).setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {findViewById(R.id.root).startAnimation(new TVOffAnimation());}});}}


main.xml:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/root"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:background="@android:color/white"    android:orientation="vertical" >    <TextView        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/hello" />    <Button        android:id="@+id/btn"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="动画" /></LinearLayout>


更多相关文章

  1. Android 获取View的位置参数:x,y和相对父容器的偏移量以及中心点
  2. RotateAnimation 设置旋转中心点、不停顿
  3. Android属性动画设置中心点

随机推荐

  1. Android(安卓)ListView
  2. Android图形解锁的绘制
  3. Android(安卓)Studio 疑难问题解决方法总
  4. 执行 Robotium 测试脚本抛出 NullPointer
  5. NdefRecord官方说明文档翻译
  6. Android(安卓)界面间传参数
  7. Android(安卓)Bitmap 改变大小
  8. Android用SQLite数据库对数据存储及操作
  9. android http post请求获取 json 图片
  10. How to read android dumpstate PROCRANK