ObjectAnimator导致ImageView消失

时间:2014-12-14 21:42:21

标签: android imageview objectanimator

我正在使用ImageView为Android中的ObjectAnimator设置动画(API 19)。我的一切都运行良好,并且它在Galaxy S3上完美显示,但在我的Nexus 7(2013 WiFi型号)上,它引起了问题。

目标是让图像使用rotateY围绕其Y轴旋转360°。但是,在Nexus 7上,在75°和105°之间,图像消失。我的drawable是从PNG创建的,相关代码如下。

查看:

<ImageView
    android:id="@+id/login_logo"
    android:layout_width="match_parent"
    android:layout_height="120dp"
    android:layout_marginTop="30dp"
    android:src="@drawable/mimo_logo"/>

开始动画:

ImageView image = (ImageView) findViewById(R.id.login_logo);
Animator anim = AnimatorInflater.loadAnimator(context, R.animator.flipping);
anim.setTarget(image);
anim.start();

动画本身:

<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="3000"
    android:propertyName="rotationY"
    android:repeatCount="-1"
    android:valueFrom="0"
    android:valueTo="360" />

我会努力获得实际问题的GIF,但有没有人想到为什么Nexus 7会遇到问题?

修改 这是它的样子(使用adb shell screenrecord录制):

http://f.cl.ly/items/1g1S2z3p3J2a33210M3s/rotateY.gif

1 个答案:

答案 0 :(得分:0)

尝试使用:image.setCameraDistance(float)方法。

来自文档:

  

例如,相机的距离会影响3D变换   绕X轴和Y轴旋转。如果是rotationX或者旋转   属性已更改,此视图很大(超过一半大小   屏幕),建议始终使用相机距离   它大于高度(X轴旋转​​)或宽度(Y轴)   旋转)这个观点。

     

如果要指定导致视觉上一致的距离   不同密度的结果,使用以下公式:

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