星空网 > 软件开发 > 操作系统

android 自定义动画

android自定义动画注意是继承Animation,重写里面的initialize和applyTransformation,在initialize方法做一些初始化的工作,在applyTransformation方法进行相应的轨阵变化即可!

直接上demo!

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;

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();
}

// 生成Transformation
@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);
camera.rotateY(mCenterY);
} else {
//camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
camera.rotateY(-mCenterY);
}
camera.rotateY(degrees);
// 取得变换后的矩阵
camera.getMatrix(matrix);
camera.restore();

matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}
}

这是一个模仿3D旋转动画的效果,下面是调用方法,mSecondMenuLayout指的是要开始动画的view

/**
*
* @param start 开始角度
* @param end 结束角度
*/
private void applyRotation(float start, float end) {

// 计算中心点
final float centerX = mSecondMenuLayout.getWidth() / 2.0f;
// final float centerY = mSecondMenuLayout.getHeight() /2.0f;
final Rotate3dAnimation rotation = new Rotate3dAnimation(start, end,
centerX, 360, 310.0f, true);
//设置动画的持续时间
rotation.setDuration(1000);
//设置动画完成后是否保留原样
rotation.setFillAfter(false);
//设置动画插补器
rotation.setInterpolator(new AccelerateDecelerateInterpolator());
//设置动画监听
rotation.setAnimationListener(mAnimListener);
mSecondMenuLayout.startAnimation(rotation);
}




原标题:android 自定义动画

关键词:Android

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

疫情下中国首次成为欧盟第一大贸易伙伴:https://www.ikjzd.com/articles/138037
​电商征税倒计时!税务总局系统大升级:https://www.ikjzd.com/articles/138038
亚马逊又颁新规,大规模清零冻结资金,你的店铺还好吗?:https://www.ikjzd.com/articles/138039
请查收!亚马逊2020年发展复盘:https://www.ikjzd.com/articles/138040
令人咋舌!亚马逊库存指标引争议,FBA发货何时自由:https://www.ikjzd.com/articles/138041
赶紧自查listing产品描述!eBay一卖家违规销售或面临牢狱之灾:https://www.ikjzd.com/articles/138042
三百元以内千兆路由器怎么选择?:https://www.vstour.cn/a/363184.html
千岛湖绿城度假酒店的简介:https://www.vstour.cn/a/363185.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流