简体   繁体   English

某些设备上的Animator / AnimatorSet问题

[英]Animator/AnimatorSet issue on some devices

I have made some tests with the ObjectAnimator class on some devices and everything is OK except for one device : Huawei P8 Lite 2017. 我在某些设备上使用ObjectAnimator类进行了一些测试,除了一台设备外,一切正常:华为P8 Lite 2017。

On this device, the View "disappears" when the animation starts and "appears" at the end. 在此设备上,视图在动画开始时“消失”并在结束时“显示”。 The issue appears only when I'm using AnimatorSet/Animator (Java code or XML), but animations which use the old Animation class (TranslateAnimation, AlphaAnimation...) are working well. 只有在我使用AnimatorSet / Animator(Java代码或XML)时才会出现此问题,但使用旧动画类(TranslateAnimation,AlphaAnimation ...)的动画效果很好。

Here is the list of devices where there is no issue : Nexus 5 Nexus 5X Nexus 9 HTC One M9 Samsung GS4 Pixel XL Alcatel OneTouch Idol 5 以下是没有问题的设备列表:Nexus 5 Nexus 5X Nexus 9 HTC One M9三星GS4 Pixel XL阿尔卡特OneTouch偶像5

What is the problem with this Huawei ? 这个华为有什么问题?

Edit : I have made some other tests, the issue seems to be only with Rotation animation. 编辑 :我做了一些其他测试,问题似乎只有旋转动画。

ObjectAnimator r = ObjectAnimator.ofFloat(myView, View.ROTATION_Y, 540);
r.setDuration(5000);
r.start();

works on every devices except the Huawei. 适用于华为以外的所有设备。

If I replace ROTATION_Y by ALPHA or TRANSLATION_X or Y, it is working on the Huawei. 如果我用ALPHA或TRANSLATION_X或Y替换ROTATION_Y,它正在使用华为。

Here is a link with more or less the same issue : ObjectAnimator causes ImageView to disappear 这是一个或多或少相同问题的链接: ObjectAnimator导致ImageView消失

I had the same problem with Huawei devices (P9 Lite). 华为设备(P9 Lite)也遇到了同样的问题。

The problem is "camera distance" during transformation. 转换期间的问题是“相机距离”。 Default value for camera distance for Huawei is too small and you should set it by code: 华为相机距离的默认值太小,您应该按代码设置:

image.setCameraDistance(float) 

From documentation: 来自文档:

If you want to specify a distance that leads to visually consistent results across various densities, use the following formula: 如果要指定在不同密度下导致视觉上一致的结果的距离,请使用以下公式:

float scale = context.getResources().getDisplayMetrics().density;
 view.setCameraDistance(distance * scale);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM