源码之3D翻转效果
通过此方法调用:applyRotation(x,y);
x和y是翻转角度
void applyRotation(float start, float end) {
final float centerY = mContainer.getWidth();
final float centerX = mContainer.getHeight();
Rotate3dAnimation rotation = new Rotate3dAnimation(start, end, centerX, centerY, 310.0f, true);
rotation.setDuration(500);
rotation.setFillAfter(true);
rotation.setInterpolator(new AccelerateInterpolator());
rotation.setAnimationListener(new DisplayNextView());
mContainer.startAnimation(rotation);
}
private final class DisplayNextView implements Animation.AnimationListener {
public void onAnimationStart(Animation animation) {
}
public void onAnimationEnd(Animation animation) {
mContainer.post(new SwapViews());
}
public void onAnimationRepeat(Animation animation) {
}
}
private final class SwapViews implements Runnable {
public void run() {
final float centerX = mContainer.getWidth();
final float centerY = mContainer.getHeight();
Rotate3dAnimation rotation;
rotation = new Rotate3dAnimation(90, 360, centerX, centerY, 310.0f, false);
setAdapter();
rotation.setDuration(1000);
rotation.setFillAfter(true);
rotation.setInterpolator(new DecelerateInterpolator());
mContainer.startAnimation(rotation);
}
}
package com.cyberstar.pad.util;
import android.graphics.Camera;
import android.graphics.Matrix;
import android.view.animation.Animation;
import android.view.animation.Transformation;
/**
* An animation that rotates the view on the Y axis between two specified angles.
* This animation also adds a translation on the Z axis (depth) to improve the effect.
*/
public class Rotate3dAnimation extends Animation {
private final float mFromDegrees;
private final float mToDegrees;
private final float mCenterX;
private final float mCenterY;
private final float mDepthZ;
private final boolean mReverse;
private Camera mCamera;
/**
* Creates a new 3D rotation on the Y axis. The rotation is defined by its
* start angle and its end angle. Both angles are in degrees. The rotation
* is performed around a center point on the 2D space, definied by a pair
* of X and Y coordinates, called centerX and centerY. When the animation
* starts, a translation on the Z axis (depth) is performed. The length
* of the translation can be specified, as well as whether the translation
* should be reversed in time.
*
* @param fromDegrees the start angle of the 3D rotation
* @param toDegrees the end angle of the 3D rotation
* @param centerX the X center of the 3D rotation
* @param centerY the Y center of the 3D rotation
* @param reverse true if the translation should be reversed, false otherwise
*/
public Rotate3dAnimation(float fromDegrees, float toDegrees,
float centerX, float centerY, float depthZ, boolean reverse) {
mFromDegrees = fromDegrees;
mToDegrees = toDegrees;
mCenterX = centerX;
mCenterY = centerY;
mDepthZ = depthZ;
mReverse = reverse;
}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
mCamera = new Camera();
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
final float fromDegrees = mFromDegrees;
float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);
final float centerX = mCenterX;
final float centerY = mCenterY;
final Camera camera = mCamera;
final Matrix matrix = t.getMatrix();
camera.save();
if (mReverse) {
camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);
} else {
camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
}
camera.rotateY(degrees);
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}
}
分享到:
相关推荐
Andorid项目源码 实现demo 超爽的android抽屉效果(源码)Andorid项目源码 实现demo 超爽的android抽屉效果(源码)Andorid项目源码 实现demo 超爽的android抽屉效果(源码)Andorid项目源码 实现demo 超爽的android...
Andorid项目源码 实现 抽屉效果 案例Andorid项目源码 实现 抽屉效果 案例Andorid项目源码 实现 抽屉效果 案例Andorid项目源码 实现 抽屉效果 案例Andorid项目源码 实现 抽屉效果 案例Andorid项目源码 实现 抽屉效果 ...
安卓Android源码——Andorid科学计算器源码.zip
Andorid项目源码 实现 抽屉效果 demo案例 Andorid项目源码 实现 抽屉效果 demo案例 Andorid项目源码 实现 抽屉效果 demo案例 Andorid项目源码 实现 抽屉效果 demo案例 Andorid项目源码 实现 抽屉效果 demo案例 ...
安卓Android源码——andorid 源码北京公交线路查询(离线).rar
Android程序研发源码Andorid 科学计算器源码
安卓Android源码——andorid 源码北京公交线路查询(离线).zip
Android 应用开发源码 参考与学习使用
Andorid项目源码 仿ios音量调节的效果 案例实现Andorid项目源码 仿ios音量调节的效果 案例实现Andorid项目源码 仿ios音量调节的效果 案例实现Andorid项目源码 仿ios音量调节的效果 案例实现Andorid项目源码 仿ios...
Andorid项目源码 飞鸽传书 源码解析 参考示例Andorid项目源码 飞鸽传书 源码解析 参考示例Andorid项目源码 飞鸽传书 源码解析 参考示例Andorid项目源码 飞鸽传书 源码解析 参考示例Andorid项目源码 飞鸽传书 源码...
Andorid项目源码 ListView上下翻页效果完整版
28 Android自定义泡泡效果 源码 29 android 获取Gps信息的程序源码 30 android 超炫的图片浏览器 31 android 加载时闪烁点样式的启动画面 32 基于 Android 的英文电子词典 33 android 源码之英语单词记忆程序源码 34...
Andorid项目源码demo 飞鸽传书 源码解析 参考示例 Andorid项目源码demo 飞鸽传书 源码解析 参考示例 Andorid项目源码demo 飞鸽传书 源码解析 参考示例 Andorid项目源码demo 飞鸽传书 源码解析 参考示例 Andorid项目...
Java源码之Andorid源码:ListView例子,ListView的作用这里就不说了吧,使用相当 广泛,在流行的Andorid开发中,也被广泛应用,那么最基础的ListView是如何建立的呢?通过本例您将学会如何使用。
Android应用源码开发Demo,主要用于毕业设计学习。
Andorid项目源码 电子杂志(带翻页效果)
[开源项目]Android_炫酷的3D音乐播放器_各种特效OpenGL.zip andorid 源码北京公交线路查询(离线).zip android Gallery实现异步加载网络图片 并只加载当前停止页面图.zip Android ListView下拉刷新 Demo.zip ...
Andorid项目源码 驴友社交系统 客户端+ 服务器端 (源码)Andorid项目源码 驴友社交系统 客户端+ 服务器端 (源码)Andorid项目源码 驴友社交系统 客户端+ 服务器端 (源码)Andorid项目源码 驴友社交系统 客户端+ ...