ObjectAnimator makes ImageView disappear
I am working on animation ImageView
in Android (API 19) using ObjectAnimator
. Everything works fine for me and displays fine on Galaxy S3, but on my Nexus 7 (WiFi model of 2013) it causes problems.
The goal is to take a 360 ° image. rotation around its Y axis with rotateY
. However, on the Nexus 7, between 75 ° and 105 °, the image disappears. My drawing was created from PNG, the corresponding code is given 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"/>
Animation start:
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 the GIF file with the actual problem, but does anyone have any thoughts as to why the Nexus 7 would have problems?
EDIT:
This is what it looks like (writing using adb shell screenrecord
):
source to share
Try using the image.setCameraDistance (float) method.
From the documentation:
Camera distance affects 3D transformations such as rotations around the X and Y axes.If the rotationX or rotationY properties are changed and this view is large (more than half the screen size), it is recommended to always use a camera distance that is greater than the height (rotation of the X axis) or width ( Y-axis rotation) of this kind.
If you want to indicate the distance that visually leads to results for different densities, use the following formula:
float scale = context.getResources().getDisplayMetrics().density;
view.setCameraDistance(distance * scale);
source to share