Animator/AnimatorSet issue on some devices

五迷三道 提交于 2019-12-13 13:34:24

问题


I have made some tests with the ObjectAnimator class on some devices and everything is OK except for one device : Huawei 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.

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

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.

Here is a link with more or less the same issue : ObjectAnimator causes ImageView to disappear


回答1:


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) 

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);


来源:https://stackoverflow.com/questions/46845261/animator-animatorset-issue-on-some-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!