华为手机使用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上是可以完美使用的. 归根到底的原因,是 ...
随机推荐
- 使用Ant编译和构建项目指南
有两种方法来构建您的应用程序使用Ant构建脚本:一个用于测试/调试您的应用程序,调试模式——和一个用于构建你的最终计划发布——发布模式.不管你怎样构建你的应用程序,它必须先签名然后可以安装在一个模拟器 ...
- Android 7.0 出现 ”FileUriExposedException“ 和 ”解析包出现错误“ 异常的解决办法
问题1 :android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.xxx.xxx.xxx.rel ...
- 深入理解Linux内核-页高速缓存
页高速缓存:1.磁盘高速缓存的一种 2.一种对完整的数据页进行操作的磁盘高速缓存.3.将一页数据写到块设备的时候,内核首先检查对应的页是否已经在高速缓存中,不在就添加并填充数据.4.I\O数据的传送并 ...
- 在TypeScript中扩展JavaScript基础对象的功能
最近工作中用到,记录一下:假设我们需要一个功能,把一个数字比如10000输出为下面的字符串格式“10,000”,一般是写一个方法,那么我希望更方便一点,直接向Number类型添加一个格式化方法,比如叫 ...
- 菜鸟学Java(三)——JSTL标签之核心标签
JSTL(JSP Standard Tag Library ,JSP标准标签库)是一个实现 Web应用程序中常见的通用功能的定制标记库集,这些功能包括迭代和条件判断.数据管理格式化.XML 操作以及数 ...
- JVM profiler tools
http://docs.oracle.com/javase/7/docs/technotes/samples/hprof.html https://codeascraft.com/2015/05/12 ...
- 每日英语:Auto Makers Accelerate Efforts to Develop Self-Driving Cars
Big auto makers are steering their efforts to develop cars that drive themselves out of the labs and ...
- nginx源码分析:架构解析
nginx启动流程: 根据上面的手稿得知,nginx在循环中调用ngx_process_events_and_timers该函数来处理事件,在该函数中,最主要的一个操作是调用了ngx_process_ ...
- idea 改变version control
idea 当一个moudule拥有2个VCS的时候 如何切换其应用的VSC 如拥有 SVN 和 GIT 2个版本 ,想换回SVN则删除 git目录 将 version control vcs 设 ...
- eth0 eth0:1 eth0.1 的区别
eth0 eth0:1 和eth0.1三者的关系对应于物理网卡.子网卡.虚拟VLAN网卡的关系:物理网卡:物理网卡这里指的是服务器上实际的网络接口设备,这里我服务器上双网卡,在系统中看到的2个物理网卡 ...