---
title: "android 特效之一  电视机关闭特效"
author: "v5qqbrowser"
date: "2013-01-08T00:19:00Z"
tags: []
slug: "android"
draft: false
lastmod: "2013-01-16T12:30:30Z"
id: 1770634
url: "https://v5qqbrowser.iteye.com/blog/1770634"
---

废话不说，上代码：

1、要关闭的Activity代码：

```
public class TVOffDemo extends Activity {
	/** Called when the activity is first created. */
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		Button b = (Button) findViewById(R.id.Button01);
		b.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				View img = findViewById(R.id.layout);
				img.startAnimation(new TVOffAnimation());
			}
		});
	}
}
```

```
2、动画实现类TVOffAnimation 
```

```
public class TVOffAnimation extends Animation {

	private int halfWidth;
	private int halfHeight;

	public 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());

	}

	protected void applyTransformation(float interpolatedTime, Transformation t) {

		final Matrix matrix = t.getMatrix();
		if (interpolatedTime < 0.8) {
			matrix.preScale(1 + 0.625f * interpolatedTime, 1 - interpolatedTime / 0.8f + 0.01f,
					halfWidth, halfHeight);
		} else {
			matrix.preScale(7.5f * (1 - interpolatedTime), 0.01f, halfWidth, halfHeight);
		}
	}
}
```

下面上源码：