在一个recyclerView上实现item的立体翻转动画,魅族、小米、华为平板都试过了没问题,但是在一个7.0的华为手机上,只要一翻转item就消失了,网上发现也有其他人遇到这种问题,大概是objectAnimation的原因,于是只能尝试了用其他动画效果实现。

原先的方式是

 private void animateStart(RecyclerView.ViewHolder holder) {
L.e(TAG, "animateStart、、、");
final MyViewHolder viewHolder = (MyViewHolder) holder;
// 获取需要被执行动画的View视图对象
LinearLayout newContainer = viewHolder.container; // 从mAnimatorMap缓存中查找当前newHolder对应的itemView动画是否在执行中,如果是则终止动画
AnimatorInfo runningInfo = mAnimatorMap.get(holder);
long prevAnimPlayTime = ;
boolean firstHalf = false;
if (runningInfo != null) {
firstHalf = runningInfo.oldTextRotator != null &&
runningInfo.oldTextRotator.isRunning();
prevAnimPlayTime = firstHalf ?
runningInfo.oldTextRotator.getCurrentPlayTime() :
runningInfo.newTextRotator.getCurrentPlayTime();
runningInfo.overallAnim.cancel();
}
// 初始化背景颜色渐变的属性动画
ObjectAnimator fadeToBlack = null, fadeFromBlack;
if (runningInfo == null || firstHalf) {
int startColor = Color.WHITE;
if (runningInfo != null) {
startColor = (Integer) runningInfo.fadeToBlackAnim.getAnimatedValue();
}
fadeToBlack = ObjectAnimator.ofInt(newContainer, "backgroundColor",
startColor, Color.WHITE);
fadeToBlack.setEvaluator(mColorEvaluator);
if (runningInfo != null) {
fadeToBlack.setCurrentPlayTime(prevAnimPlayTime);
}
} fadeFromBlack = ObjectAnimator.ofInt(newContainer, "backgroundColor",
Color.WHITE, Color.WHITE);
fadeFromBlack.setEvaluator(mColorEvaluator);
if (runningInfo != null && !firstHalf) {
fadeFromBlack.setCurrentPlayTime(prevAnimPlayTime);
} //背景动画
AnimatorSet bgAnim = new AnimatorSet();
if (fadeToBlack != null) {
bgAnim.playSequentially(fadeToBlack, fadeFromBlack);
} else {
bgAnim.play(fadeFromBlack);
}
// 初始化旋转的属性动画
ObjectAnimator oldTextRotate = null, newTextRotate;
if (runningInfo == null || firstHalf) {
oldTextRotate = ObjectAnimator.ofFloat(newContainer, View.ROTATION_X, , );
oldTextRotate.setInterpolator(mAccelerateInterpolator);
if (runningInfo != null) {
oldTextRotate.setCurrentPlayTime(prevAnimPlayTime);
} else {
L.e(TAG, "runningInfo == null 444444");
} } else {
L.e(TAG, "runningInfo == null && firstHalf 333333");
}
AnimatorSet textAnim = new AnimatorSet();
if (oldTextRotate != null) {
textAnim.playSequentially(oldTextRotate);
} else {
L.e(TAG, "oldTextRotate != null");
} final RecyclerView.ViewHolder newHolder = holder;
AnimatorSet changeAnim = new AnimatorSet();
changeAnim.playTogether(bgAnim, textAnim);
changeAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
dispatchAnimationFinished(newHolder);
mAnimatorMap.remove(newHolder);
}
});
changeAnim.start();
}

后修改了翻转动画的objectAnimation的方法为:

private void animateStart(RecyclerView.ViewHolder holder) {
L.e(TAG, "animateStart、、、");
final MyViewHolder viewHolder = (MyViewHolder) holder;
// 获取需要被执行动画的View视图对象
LinearLayout newContainer = viewHolder.container; // 从mAnimatorMap缓存中查找当前newHolder对应的itemView动画是否在执行中,如果是则终止动画
AnimatorInfo runningInfo = mAnimatorMap.get(holder);
long prevAnimPlayTime = ;
boolean firstHalf = false;
if (runningInfo != null) {
firstHalf = runningInfo.oldTextRotator != null &&
runningInfo.oldTextRotator.isRunning();
prevAnimPlayTime = firstHalf ?
runningInfo.oldTextRotator.getCurrentPlayTime() :
runningInfo.newTextRotator.getCurrentPlayTime();
runningInfo.overallAnim.cancel();
}
// 初始化背景颜色渐变的属性动画
ObjectAnimator fadeToBlack = null, fadeFromBlack;
if (runningInfo == null || firstHalf) {
int startColor = Color.WHITE;
if (runningInfo != null) {
startColor = (Integer) runningInfo.fadeToBlackAnim.getAnimatedValue();
}
fadeToBlack = ObjectAnimator.ofInt(newContainer, "backgroundColor",
startColor, Color.WHITE);
fadeToBlack.setEvaluator(mColorEvaluator);
if (runningInfo != null) {
fadeToBlack.setCurrentPlayTime(prevAnimPlayTime);
}
} fadeFromBlack = ObjectAnimator.ofInt(newContainer, "backgroundColor",
Color.WHITE, Color.WHITE);
fadeFromBlack.setEvaluator(mColorEvaluator);
if (runningInfo != null && !firstHalf) {
fadeFromBlack.setCurrentPlayTime(prevAnimPlayTime);
} //背景动画
AnimatorSet bgAnim = new AnimatorSet();
if (fadeToBlack != null) {
bgAnim.playSequentially(fadeToBlack, fadeFromBlack);
} else {
bgAnim.play(fadeFromBlack);
}
startRotation(newContainer, , ); final RecyclerView.ViewHolder newHolder = holder;
AnimatorSet changeAnim = new AnimatorSet();
changeAnim.playTogether(bgAnim, textAnim);
changeAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
dispatchAnimationFinished(newHolder);
mAnimatorMap.remove(newHolder);
}
});
changeAnim.start();
} private void startRotation(LinearLayout view,float start, float end) {
// 计算中心点
final float centerX = view.getWidth() / 2.0f;
final float centerY = view.getHeight() / 2.0f;
L.d(TAG, "centerX="+centerX+", centerY="+centerY);
// Create a new 3D rotation with the supplied parameter
// The animation listener is used to trigger the next animation
//final Rotate3dAnimation rotation =new Rotate3dAnimation(start, end, centerX, centerY, 310.0f, true);
//Z轴的缩放为0
Rotate3dAnimation rotation =new Rotate3dAnimation(start, end, centerX, centerY, 0f, true);
rotation.setDuration();
rotation.setFillAfter(true);
//rotation.setInterpolator(new AccelerateInterpolator());
//匀速旋转
rotation.setInterpolator(new LinearInterpolator());
//设置监听
StartNextRotate startNext = new StartNextRotate(rotation, view);
rotation.setAnimationListener(startNext);
view.startAnimation(rotation);
} private class StartNextRotate implements Animation.AnimationListener {
private Rotate3dAnimation rotation;
private LinearLayout view; public StartNextRotate(Rotate3dAnimation rotation, LinearLayout view){
this.rotation = rotation;
this.view = view;
}
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
L.d(TAG, "onAnimationEnd......");
// view.startAnimation(rotation);//重复翻转
view.clearAnimation();
}
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
}

其中的Rotate3dAnimation是一个继承与Animation的自定义类

 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初始状态,用于restore()
camera.save();
if (mReverse) {
camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);
} else {
camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
}
//围绕X轴旋转degrees度
camera.rotateX(degrees);
//行camera中取出矩阵,赋值给matrix
camera.getMatrix(matrix);
//camera恢复到初始状态,继续用于下次的计算
camera.restore();
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}
}

Rotate3dAnimation

华为手机使用objectAnimation异常的更多相关文章

  1. EasyPusher华为手机直播推流硬编码[OMX.IMG.TOPAZ.Encoder] failed to set input port definition parameters.

    EasyPusher作为一款RTSP推送利器, 配合EasyDarwin开源流媒体服务器,在发布伊始,很快获得了广大人民群众的一致好评. 但是也有一些用户反映: EasyPusher在我的华为手机上会 ...

  2. 华为手机调试显示log日志

    华为手机默认状态手机log为关闭状态,所以看不到详细错误信息. 手机拨号*#*#2846579#*#*,进入projectmenu--后台设置--LOG设置--LOG开关--打开 勾选AP日志   C ...

  3. android studio 华为手机看不到具体的错误日志

    手机的开发人员选项打开了么,其中的 USB 调试打开了么?搞定他们并重新运行,是否能找到我们的日志?否,转到 2. 日志中是否有这样 could not disable core file gener ...

  4. 华为手机打开Logcat的方法

    华为手机默认是关闭logcat信息的,这在开发调试时当然很不方便,打开log信息的方法如下 1. 进入拨号界面输入:*#*#2846579#*#*  2. 依次选择ProjectMenu---后台设置 ...

  5. 华为手机Edittext光标(cursor)颜色修改

    华为手机的emui系统经常让人发出“可以可以,这很华为”的感叹 这两天在edittext部分也发生了这样的事情 正常edittext光标的颜色和宽度都说可以修改的,只需要通过xml中的 textCur ...

  6. Android开发华为手机无法看log日志解决方法

    Android开发华为手机无法看log日志解决方法 上班的时候,由于开发工具由Eclipse改成Android Studio后,原本的华为手机突然无法查看崩溃日志了,大家都知道,若是无法查看日志要它毛 ...

  7. mui 页面无法下滑拖拽 主要体现在华为手机浏览器

    项目做到中期遇到一个问题,华为手机有些页面显示不全且无法下滑. 因为之前一直用的Google浏览器的模拟模式进行开发和调试的,一直未发现这个问题. 刚开始 选用mui的下拉刷新上拉加载的方式来进行页面 ...

  8. 华为手机浏览器 onclick失灵的问题

    开发h5 遇到的问题是华为浏览器onclick 点击失灵. 下面这个网站是检查 浏览器是否支持es6语法的网站 http://ruanyf.github.io/es-checker/index.cn. ...

  9. 解决linux ubuntu不能识别华为手机的问题--升级内核

    敝人手中有一个华为mate8,但是debian, ubuntu及一系列衍生版均不能识别.只能识别出一个华为手机助手,但是无法使用华为的内置存贮. 在fedora上是可以完美使用的. 归根到底的原因,是 ...

随机推荐

  1. 分布式系统的那些事儿(四) - MQ时代的通信

    之前在讲RPC通信的各种好处,特别好用,但是RPC并不是万能的,也并不是适用于各种场景的,因为他是同步的:现如今很多场景下的调用都是异步的,系统A调用B后,并不需要知道B的结果,而且对B的结果无所谓, ...

  2. Atitit 软件体系的进化,是否需要一个处理中心

    Atitit 软件体系的进化,是否需要一个处理中心 1.1. 进化树上是没有主干的..1 1.2. ,软件进化的行为1::主要就是给新的应用编写新的程序.1 1.3. ,软件进化的行为2::软件的维护 ...

  3. BLIST,BindingSource

    //gridControl1.DataSource = BList; //BindingSource bs = new BindingSource(); //bs.DataSource = BList ...

  4. ubuntu 编译android 源码笔记

    已经验证,可以编译成功.过程中会碰到一些编译错误,安装好依赖环境,可以解决. 1.splite压缩包的合并,解压缩,md5验证 http://pan.baidu.com/s/1bnG1NtX kitk ...

  5. Linux学习笔记(九)

    <span style="font-size:18px;">本人使用的是centos 因为用使用些特殊命令.不得不改动系统的时间这里总结例如以下: date 查看系统时 ...

  6. 安装pydiction

    pydiction用来实现代码补全和语法提示功能.pydiction不能通过apt安装,需要自行下载安装. 在GitHub下载源码,可以使用Git迁出到本地,或者下载zip包自行解压,地址为:http ...

  7. Java运行时动态加载类之ClassLoader

    https://blog.csdn.net/fjssharpsword/article/details/64922083 *************************************** ...

  8. SpringBoot 跨域 Access-Control-Allow-Origin 问题

    https://blog.csdn.net/taoism_jerry/article/details/79695336 **************************************** ...

  9. mysql memory engine

    前言 刚刚遇到了mysql无法插入数据,报错:the table xxx is full. 查询原因,是xx表使用了memory engine,其中mysql的memory engine中有max_h ...

  10. 纯CSS3悬停图标旋转导航动画代码

    分享一款纯CSS3悬停图标旋转导航动画代码.这是一款鼠标移到图标上动画旋转显示导航菜单.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div id="x_con ...