华为手机使用objectAnimation异常
在一个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异常的更多相关文章
- EasyPusher华为手机直播推流硬编码[OMX.IMG.TOPAZ.Encoder] failed to set input port definition parameters.
EasyPusher作为一款RTSP推送利器, 配合EasyDarwin开源流媒体服务器,在发布伊始,很快获得了广大人民群众的一致好评. 但是也有一些用户反映: EasyPusher在我的华为手机上会 ...
- 华为手机调试显示log日志
华为手机默认状态手机log为关闭状态,所以看不到详细错误信息. 手机拨号*#*#2846579#*#*,进入projectmenu--后台设置--LOG设置--LOG开关--打开 勾选AP日志 C ...
- android studio 华为手机看不到具体的错误日志
手机的开发人员选项打开了么,其中的 USB 调试打开了么?搞定他们并重新运行,是否能找到我们的日志?否,转到 2. 日志中是否有这样 could not disable core file gener ...
- 华为手机打开Logcat的方法
华为手机默认是关闭logcat信息的,这在开发调试时当然很不方便,打开log信息的方法如下 1. 进入拨号界面输入:*#*#2846579#*#* 2. 依次选择ProjectMenu---后台设置 ...
- 华为手机Edittext光标(cursor)颜色修改
华为手机的emui系统经常让人发出“可以可以,这很华为”的感叹 这两天在edittext部分也发生了这样的事情 正常edittext光标的颜色和宽度都说可以修改的,只需要通过xml中的 textCur ...
- Android开发华为手机无法看log日志解决方法
Android开发华为手机无法看log日志解决方法 上班的时候,由于开发工具由Eclipse改成Android Studio后,原本的华为手机突然无法查看崩溃日志了,大家都知道,若是无法查看日志要它毛 ...
- mui 页面无法下滑拖拽 主要体现在华为手机浏览器
项目做到中期遇到一个问题,华为手机有些页面显示不全且无法下滑. 因为之前一直用的Google浏览器的模拟模式进行开发和调试的,一直未发现这个问题. 刚开始 选用mui的下拉刷新上拉加载的方式来进行页面 ...
- 华为手机浏览器 onclick失灵的问题
开发h5 遇到的问题是华为浏览器onclick 点击失灵. 下面这个网站是检查 浏览器是否支持es6语法的网站 http://ruanyf.github.io/es-checker/index.cn. ...
- 解决linux ubuntu不能识别华为手机的问题--升级内核
敝人手中有一个华为mate8,但是debian, ubuntu及一系列衍生版均不能识别.只能识别出一个华为手机助手,但是无法使用华为的内置存贮. 在fedora上是可以完美使用的. 归根到底的原因,是 ...
随机推荐
- jsp页面中的EL表达式不被解析的问题
原因:问题在web.xml配置文件上,web.xml声明部分一般分为如下版本的xsd, web-app_2_2.xsd web-app_2_3.xsd web-app_2_4.xsd web-app_ ...
- Android Webview SSL 自签名安全校验解决方案
服务器证书校验主要针对 WebView 的安全问题. 在 app 中需要通过 WebView 访问 url,因为服务器采用的自签名证书,而不是 ca 认证,使用 WebView 加载 url 的时候会 ...
- ubuntu for win10 里运行apache+php
一直想试试ubuntu for win10中运行网站测试一下,弄了好久,今天终于基本弄明白了, ubuntu for win10里的IP就是外面WIN10的IP,在里面建立网站了可以直接在外面WIN1 ...
- angular学习笔记(三十)-指令(4)-transclude
本篇主要介绍指令的transclude属性: transclude的值有三个: 1.transclude:false(默认值) 不启用transclude功能. 2.transclude:true 启 ...
- a,input,button点击的时候出现蓝色的边框
a,button,input{ -webkit-tap-highlight-color: rgba(0, 0, 0, 0); -webkit-user-modify: read-write-plain ...
- FIDDLER的使用方法及技巧总结(连载五)FIDDLER的一些故障排除
五.FIDDLER的一些故障排除
- MFC工程说明readme
======================================================================== MICROSOFT FOUNDATION CLASS ...
- Unable to locate \.nuget\NuGet.exe 问题解决办法之一(转)
问题出现的原因是项目下.nuget文件夹下NuGet.exe文件夹不存在导致的 解决办法: 1.右键编辑NuGet.targets文件 将下载NuGet.exe的配置节点DownloadNuGetEx ...
- libXext.so.6: cannot open shared object file:
在64位的centos安装64位的oracle的时候,有时候会出现“libXext.so.6: cannot open shared object file:”的错误. 这个原因主要是oracle在安 ...
- 16款纯CSS3实现的loading加载动画
分享16款纯CSS3实现的loading加载动画.这是一款实用的可替代GIF格式图片的CSS3加载动画代码.效果图如下: 在线预览 源码下载 实现的代码. html代码: <div clas ...