search
HomeWeb Front-endHTML Tutorial自定义Animation、3D动画旋转_html/css_WEB-ITnose

    

/**

 * 自定义动画,利用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();

}

}


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the purpose of the <datalist> element?What is the purpose of the <datalist> element?Mar 21, 2025 pm 12:33 PM

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

What is the purpose of the <progress> element?What is the purpose of the <progress> element?Mar 21, 2025 pm 12:34 PM

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

What is the purpose of the <meter> element?What is the purpose of the <meter> element?Mar 21, 2025 pm 12:35 PM

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

What is the viewport meta tag? Why is it important for responsive design?What is the viewport meta tag? Why is it important for responsive design?Mar 20, 2025 pm 05:56 PM

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.

What is the purpose of the <iframe> tag? What are the security considerations when using it?What is the purpose of the <iframe> tag? What are the security considerations when using it?Mar 20, 2025 pm 06:05 PM

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.

How do I use the HTML5 <time> element to represent dates and times semantically?How do I use the HTML5 <time> element to represent dates and times semantically?Mar 12, 2025 pm 04:05 PM

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

What are the best practices for cross-browser compatibility in HTML5?What are the best practices for cross-browser compatibility in HTML5?Mar 17, 2025 pm 12:20 PM

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

How do I use HTML5 form validation attributes to validate user input?How do I use HTML5 form validation attributes to validate user input?Mar 17, 2025 pm 12:27 PM

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

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

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

Dreamweaver Mac version

Visual web development tools