问题
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.
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.
View:
<ImageView
android:id="@+id/login_logo"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_marginTop="30dp"
android:src="@drawable/mimo_logo"/>
Starting the animation:
ImageView image = (ImageView) findViewById(R.id.login_logo);
Animator anim = AnimatorInflater.loadAnimator(context, R.animator.flipping);
anim.setTarget(image);
anim.start();
And the animation itself:
<?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" />
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?
EDIT:
Here's what it looks like (recording using adb shell screenrecord
):
回答1:
Try to use: image.setCameraDistance(float) method.
From documentation:
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.
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/27474467/objectanimator-causes-imageview-to-disappear