华为手机使用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上是可以完美使用的. 归根到底的原因,是 ... 
随机推荐
- Java:多线程,Exchanger同步器
			1. 背景 类java.util.concurrent.Exchanger提供了一个同步点,在这个同步点,一对线程可以交换数据.每个线程通过exchange()方法的入口提供数据给他的伙伴线程,并接收 ... 
- Atitit 图像处理类库安装与安装模式的前世今生与未来大趋势attilax总结.docx
			Atitit 图像处理类库安装与安装模式的前世今生与未来大趋势attilax总结.docx 1. 安装的原理,主要是解压,复制,设置三大步1 2. 目前我们常见的三大种安装模式,二进制模式与源码安装模 ... 
- openssl之EVP系列之13---EVP_Open系列函数介绍
			openssl之EVP系列之13---EVP_Open系列函数介绍 ---依据openssl doc/crypto/EVP_OpenInit.pod翻译和自己的理解写成 (作者:Dra ... 
- centos chroot使用
			chroot命令用来在指定的根目录下运行指令.chroot,即 change root directory (更改 root 目录).在 linux 系统中,系统默认的目录结构都是以/,即是以根 (r ... 
- haproxy 配置https 同时技持443 80端口
			确定haproxy支持https [root@c01 sbin]# ldd haproxy |grep ssl libssl.so.10 => /usr/lib64/libssl.so.10 ( ... 
- HTML5学习笔记(二十四):DOM扩展
			DOM扩展 DOM标准扩展最开始都是来自各个浏览器的自定义扩展DOM的功能,后被收录为标准的DOM相关API. 本笔记只记录被各大浏览器支持的标准扩展,对于特定浏览器的专有扩展不讨论. 选择符API ... 
- HTML5学习笔记(九):选择器详解
			在前面的笔记中我们已经接触过几种常见的选择器,本笔记我们将深入了解CSS的选择器. 元素选择器 最常见的 CSS 选择器是元素选择器.换句话说,文档的元素就是最基本的选择器.在 W3C 标准中,元素选 ... 
- [AWS vs Azure] 云计算里AWS和Azure的探究(6) - Amazon Simple Storage Service 和 Microsoft Azure Blob Storage
			这几天Nasuni公司出了一份报告,分析了各个云厂商的云存储的性能,包括Amazon S3,Azure Blob Storage, Google Drive, HP以及Rackspace.其中性能上A ... 
- 每日英语:The Invasion of the Online Tutors
			It's a nightly dilemma in many households: A student hits a wall doing homework, and parents are too ... 
- DIOCP3-数据库DEMO
			socket-Coder\DataModuleDEMO\ 本DEMO演示数据库的简单使用,其他功能需要自己扩展. 将工程的输出路径设置到socket-Coder\DataModuleDEMO\ ... 
