ObjectAnimator导致ImageView消失 [英] ObjectAnimator causes ImageView to disappear

查看:543
本文介绍了ObjectAnimator导致ImageView消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ObjectAnimator 在Android(API 19)中制作动画 ImageView 。我的一切都运行良好,它在Galaxy S3上完美显示,但在我的Nexus 7(2013 WiFi型号)上,它会导致问题。

I'm working on animating an ImageView in Android (API 19), using ObjectAnimator. I've got everything working well, and it displays perfectly on a Galaxy S3, but on my Nexus 7 (2013 WiFi model) it's causing issues.

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

The goal is to have an image do a full 360° rotation around its Y-axis using rotateY. However, on the Nexus 7, between 75° and 105°, the image disappears. My drawable was created from a PNG, and the relevant code is below.

查看:

<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会遇到问题吗?

I'll work on getting a GIF of the actual issue, but does anyone have any thoughts why the Nexus 7 would be having issues?

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

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

推荐答案

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

Try to use: image.setCameraDistance(float) method.

来自文档:


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

The camera's distance affects 3D transformations, for instance rotations around the X and Y axis. If the rotationX or rotationY properties are changed and this view is large (more than half the size of the screen), it is recommended to always use a camera distance that's greater than the height (X axis rotation) or the width (Y axis rotation) of this view.

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

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

这篇关于ObjectAnimator导致ImageView消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆