【android】用camera实现vi
发布时间:2019-08-30 08:31:09编辑:auto阅读(1552)
使用Camera实现3D变换效果
最后来简单介绍下android提供的android.graphics.Camera类,通过该类可以在2D条件下实现3D动画效果,该类可以看做一个视图显示的3D空间,然后可以在里面做各种操作。把上面的ViewAnimation修改为如下实现可以具体看看Camera的功能:
- class ViewAnimation extends Animation {
- int mCenterX;
- int mCenterY;
- Camera camera = new Camera();
- public ViewAnimation() {
- }
-
- @Override
- public void initialize(int width, int height, int parentWidth,
- int parentHeight) {
- super.initialize(width, height, parentWidth, parentHeight);
-
- mCenterX = width/2;
- mCenterY = height/2;
- setDuration(2500);
- setFillAfter(true);
- setInterpolator(new LinearInterpolator());
- }
-
- @Override
- protected void applyTransformation(float interpolatedTime,
- Transformation t) {
-
-
-
-
-
-
- final Matrix matrix = t.getMatrix();
- camera.save();
- camera.translate(0.0f, 0.0f, (1300 - 1300.0f * interpolatedTime));
- camera.rotateY(360 * interpolatedTime);
- camera.getMatrix(matrix);
- matrix.preTranslate(-mCenterX, -mCenterY);
- matrix.postTranslate(mCenterX, mCenterY);
- camera.restore();
- }
- }
camera.translate(0.0f, 0.0f, (1300 - 1300.0f * interpolatedTime))在第一次调用的时候interpolatedTime值为0,相当于把ImageView在Z轴后移1300像素,然后逐步的往前移动到0,同时camera.rotateY(360 * interpolatedTime)函数又把ImageView沿Y轴翻转360度,最终效果如下:
下图是中移动的Ophone的截图,当然,同样兼容android,
关键字: