/**
* 自定义动画,利用Camera可以实现3D效果 在Activity中调用一下方法 image = (ImageView)
* findViewById(R.id.image) ; Bitmap bitmap =
* BitmapFactory.decodeResource(getResources(), R.drawable.main_back_pic) ;
* image.setImageBitmap(bitmap); image.startAnimation(new
* MyAnimation(bitmap.getWidth()/2, bitmap.getHeight()/2, 3500));
* */
public class MyAnimation extends Animation {
private int width;
private int height;
private int duration;// 持续的时间
private Camera camera = new Camera();
public MyAnimation(int width, int height, int duration) {
this.height = height;
this.width = width;
this.duration = duration;
}
@Override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
setDuration(duration);// 设置动画的执行时间
setFillAfter(true);// 动画结束后动画停留在动画的最后一帧,setFillBefore(true):动画结束后停留在第一帧
// 动画设置成匀速运动,设置运动状态,在XML文件里设置没有作用,必须用在Java代码中设置
setInterpolator(new LinearInterpolator());
super.initialize(width, height, parentWidth, parentHeight);
}
@Override
protected void applyTransformation(float interpolatedTime,
Transformation trans) {
/**
* 此方法中的两个参数,第一个interpolatedTime,代表了抽象动画进行的时间,不管时间进行多久,其参数数值都是从0到1
* 0代表动画开始,1代表动画结束, Transformation是对动画所做的改变 Camera提供的方法:getMatrix(Matrix
* matrix)将Camera所做的变化应用到matrix上 rotateX(float deg)将目标组件沿着X轴进行旋转
* rotateY(float deg)将目标组件沿着Y轴进行旋转 totateZ(float deg)将组件沿着Z轴进行旋转
* translate(float x,float y,float z)将目标组件在三维空间内进行位移转换
* applyToCanvas(Canvas canvas)把Camera所做的变化应用到Canvas
* */
super.applyTransformation(interpolatedTime, trans);
camera.save();
// 把目标组件在三维视图中进行切换
// 在第一次调用的时候nterpolatedTime的值为0,相当于把view移动了10个像素,以后越来越少,一个周期过去,再变向转动
camera.translate(0.0f, 0.0f, (10 - 10 * interpolatedTime));
// camera.rotateX(360 * interpolatedTime);
camera.rotateY(360 * interpolatedTime);
// camera.rotateZ(360 * interpolatedTime);
Matrix matrix = trans.getMatrix();
camera.getMatrix(matrix);
// preTranslate是指在setScale前,平移,postTranslate是指在setScale后平移
// 注意他们参数是平移的距离,而不是平移目的地的坐标!
// 由于缩放是以(0,0)为中心的,所以为了把界面的中心与(0,0)对齐,就要preTranslate(-centerX,
// -centerY),
// setScale完成后,调用postTranslate(centerX,
// centerY),再把图片移回来,这样看到的动画效果就是activity的界面图片从中心不停的缩放了
// centerX和centerY是界面中心的坐标
matrix.preTranslate(-width, -height);
matrix.postTranslate(width, height);
camera.restore();
}
}

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Zend Studio 13.0.1
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools