3

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

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Carson Darling
  • 310
  • 1
  • 9
  • so it disappears because the system doesn't know what the back of it looks like – Blundell Dec 14 '14 at 22:01
  • Once it rotates past 105°, it looks totally fine (showing the back side, with the image backwards). It's only while the image is actually "on edge" that I'm having issues – Carson Darling Dec 16 '14 at 14:53
  • Did you try to increase the duration to see if the interpolated steps might be just really tricky? Increase it to 10 or 20 secs and see if the look changes or if the problem persists. – Stefan Hoth Dec 16 '14 at 18:01
  • Just confirmed that even with a 30 second duration, the image still disappears, and still only on the Nexus 7. I did realize however, the the S3 is running Android 4.3 vs the Nexus 7's 5.0.1. I'm starting to look for other devices that are running Lollipop to check if it's Lollipop specific. – Carson Darling Dec 16 '14 at 23:49
  • And to follow up, just tested on a 2012 Nexus 7 (WiFi), running Lollipop, and the rotation showed up perfectly. – Carson Darling Dec 18 '14 at 16:00

1 Answers1

0

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