某些设备上的Animator / AnimatorSet问题 [英] Animator/AnimatorSet issue on some devices
问题描述
我在某些设备上使用ObjectAnimator类进行了一些测试,除一个设备外,其他一切正常:华为P8 Lite 2017。
I have made some tests with the ObjectAnimator class on some devices and everything is OK except for one device : Huawei P8 Lite 2017.
在此设备上,View动画开始时消失,结束时出现。
仅当我使用AnimatorSet / Animator(Java代码或XML),但使用旧的Animation类(TranslateAnimation,AlphaAnimation ...)的动画运行良好时,才会出现此问题。
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.
以下是没有问题的设备列表:
Nexus 5
Nexus 5X
Nexus 9
HTC One M9
Samsung GS4
Pixel XL
阿尔卡特OneTouch Idol 5
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
华为有什么问题?
编辑:
我进行了其他一些测试,该问题似乎仅与旋转动画有关。
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.
如果我将ROTATION_Y替换为ALPHA或TRANSLATION_X或Y,则表明它正在华为上运行。
If I replace ROTATION_Y by ALPHA or TRANSLATION_X or Y, it is working on the Huawei.
以下是一个链接,链接的问题大致相同:
ObjectAnimator导致ImageView消失
Here is a link with more or less the same issue : ObjectAnimator causes ImageView to disappear
推荐答案
我在使用华为设备(P9 Lite)时遇到了同样的问题。
I had the same problem with Huawei devices (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)
来自文档:
如果要指定一个距离,以使各种密度的
结果在视觉上保持一致,请使用以下公式:
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);
这篇关于某些设备上的Animator / AnimatorSet问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!