使
用
Animation中的
Camera
构造伪
3D动画效果
水平翻转效果。
主要是想用于设计一个新的翻页方案。
或2个界面之间的切换方案
关键代码已标红
--------------
代码
package dk.demo.anim;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
public class TwoSidedViewActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ImageView img1=new ImageView(this);
img1.setImageResource(R.drawable.img1);
ImageView img2=new ImageView(this);
img2.setImageResource(R.drawable.img2);
TwoSidedView tsv=new TwoSidedView(this, img1, img2, 2500);
setContentView(tsv);
}
}
package dk.demo.anim;
import android.content.Context;
import android.graphics.Camera;
import android.graphics.Matrix;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.Transformation;
import android.widget.RelativeLayout;
public class TwoSidedView extends RelativeLayout{
private View frontView;
private View backView;
private int duration;
ViewAnimation animFront;
ViewAnimation animBack;
public TwoSidedView(Context context,View frontView,View backView,int duration) {
super(context);
this.frontView=frontView;
this.backView=backView;
animFront=new ViewAnimation();
animFront.flag=ViewAnimation.FRONT_ANIM;
animFront.setFillAfter(true);
animBack=new ViewAnimation();
animBack.flag=ViewAnimation.BACK_ANIM;
animBack.setFillAfter(true);
this.duration=duration;
this.addView(frontView);
this.addView(backView);
frontView.setOnClickListener(mOnclickListener);
backView.setOnClickListener(mOnclickListener);
this.removeAllViews();
this.addView(backView);
this.addView(frontView);
}
View.OnClickListener mOnclickListener=new View.OnClickListener() {
@Override
public void onClick(View v) {
if(v.equals(frontView))
{
frontView.startAnimation(animFront);
backView.startAnimation(animBack);
}
//
else
//
{
//
frontView.startAnimation(animBack);
//
backView.startAnimation(animFront);
//
}
//
}
};
class ViewAnimation extends Animation {
private static final int FRONT_ANIM=0;
private static final int BACK_ANIM=1;
int mCenterX;//记录
View
的中间坐标
int mCenterY;
Camera camera = new Camera();
int flag;
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(duration);
setFillAfter(true);
setInterpolator(new LinearInterpolator());
}
@Override
protected void applyTransformation(float interpolatedTime,
Transformation t) {
final Matrix matrix = t.getMatrix();
camera.save();
if(flag==FRONT_ANIM )
{
if(interpolatedTime<=(0.5))
{
camera.rotateY( interpolatedTime*2*90);
//第一个view 在动画时间的前半段旋转90° 和屏幕垂直(不可见)
//System.out.println("time:"+interpolatedTime*2*90);
}
else
{
camera.rotateY(90);
}
}
else if(flag==BACK_ANIM )
{
if(interpolatedTime>=0.5)
{
camera.rotateY((float)(270+ (interpolatedTime-0.5)*90*2));
//第二个view
在动画时间的后半段从270°旋转至360°
//即从垂直于屏幕 旋转到与屏幕平行
//由不可见变为可见
}
else
{
camera.rotateY(270);
}
}
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-mCenterX, -mCenterY);
matrix.postTranslate(mCenterX, mCenterY);
}
}
}
分享到:
相关推荐
使用animation类动画效果构建手机页面的翻页效果!
使用Animation-list实现等待加载动画效果,简单demo,适合新手学习使用Animation-list
Aurora 3D Animation Maker一款专业的3D文本动画制作软件,与其同类的软件还有Xara 3D及Cool3D,使用它能够让你轻松制作出具有专业水准的3D动画效果,能够让初学者在最短的时间创作出符合要求的动画,丰富的工具...
用animation实现UIView动画效果,简单上中下移动
Simple Mirror Animation Unity动画镜像翻转插件,Mirroring character animations should not just be a Mecanim only feature. With the Simple Mirror Animation asset, legacy character animation mirroring is...
css3弹力球动画animation属性制作3D弹力球弹跳动画效果
Aurora 3D Animation Maker内置了很多动画效果,有多种动态背景,是制作三维动画和旗帜的最佳选择。同时还具有动出导出功能,可以把你制作出来的动画和产品宣传等导出画flash格式发布到网上,得到更多的暴光。 ...
Android中并没有提供直接做3D翻转的动画,所以关于3D翻转的动画效果需要我们自己实现,那么我们首先来分析一下Animation 和 Transformation。 Animation动画的主要接口,其中主要定义了动画的一些属性比如开始时间,...
第二个应用于手机硬件中的相机相关的操作,本文讲述的是利用第一个Camera类实现中轴3D转换的卡牌翻转效果,开始之前,先看一下Android系统中的坐标系: 对应于三维坐标系中的三个方向,Camera提供了三种旋转方法: ...
点击图片,图片翻转的动画效果。 主要是通过继承Animation类来实现翻转动画。
css中的animation属性轮播图动画效果
使用animation完成魔方的生成以及旋转效果,可以让参考者大致了解怎么使用animation完成一个小动画
安装完成后,将注册机复制到C:\Program Files\Aurora3D\Animation3D目录下面,运行注册机,在Product中选择Aurora 3D Animation Maker V11.0,先点击PATCH按钮,为Animation3D.exe打补丁,再使用注册机生成的...
用Core Animation写的一段ios动画效果
厌烦了然后出现一片空白的等待页面?本款插件能够为您带来震撼的html5页面过渡切换效果,各种各样的效果几十种,使用css3 animation属性和html5技术打造而成。
三款非常酷炫的网页Loading加载进度条动画效果。使用css3 animation技术制作而成。
在android中,Animation都是二维的,但是可以通过Camera这种方式来实现类3D 的变换,这是ApiDemos中的一部分,抽出来的!
Aurora 3D Animation Maker 2020是一个功能强大但易于使用的应用程序,允许您创建美丽和引人注目的3D动画,将您的文本或标识转换为原创和专业的创作。 这是一个功能齐全的工具,它提供了一个全面的环境和一套完整的...
主要为大家详细介绍了vue+animation实现翻页动画,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下