Android 4.4 animation animation blinks when animating a subview

I noticed a very strange situation when the Android application migrated in 4.4. Suddenly, the rotation animation of my HUD component began to flash and did not work. I am trying to rotate an object as follows:

rotateAnimation = new RotateAnimation(180, 360, Animation.RELATIVE_TO_SELF,
        0.5f,  Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setDuration(1000);
rotateAnimation.setRepeatCount(Animation.INFINITE);
rotateAnimation.setRepeatMode(Animation.RESTART);

and

public static void rotate(final View view) {

if(view.getAnimation() != null) {
    view.getAnimation().cancel();
    view.clearAnimation();
}

view.setAnimation(rotateAnimation);
view.getAnimation().start();

}

The above code works fine when used in any other non-nested object, but when used for ImageViewincluded in the include tag, it just doesn't work. It is strange that other animations on the same object, called in the same context, work. Is this a mistake 4.4? I Turn on the view as follows:

    <include
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        layout="@layout/view_trip_hud"
        android:layout_gravity="bottom"/>

And the HUD component itself looks like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:alpha="0.6"
    android:background="@drawable/background_texture_dark"
    tools:context=".app.ui.fragment.TripSummaryFragment"
    android:gravity="center_vertical|left"
    android:id="@+id/relativeLayoutHUDContainer">


    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center_vertical"
        android:padding="@dimen/ui_default_element_margin">

        <ImageView
                android:id="@+id/imageViewTrackingStatus"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/status_preparing"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true" />

        <TextView
                android:id="@+id/textViewDriveQuality"
                style="@style/HUDFont"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:text="@string/track_status_inactive"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true" />

    </LinearLayout>

    <view
        android:id="@+id/linearLayoutHUDCurrentSpeed"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        class="pl.com.infinitysoftware.carassistant.util.ui.HUDBlockLayout"
        style="@style/HUDBlock"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="@dimen/ui_min_element_margin">

    <TextView
            android:id="@+id/textViewCurrentSpeed"
            style="@style/HUDFont"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:text="-,-Km/h"
            android:clickable="false"
            android:layout_gravity="center_vertical"
            android:gravity="center_vertical"/>
        </view>

    <view
        class="pl.com.infinitysoftware.carassistant.util.ui.HUDBlockLayout"
        style="@style/HUDBlock"
        android:id="@+id/linearLayoutHUDCurrentDistance"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/linearLayoutHUDCurrentSpeed"
        android:layout_marginLeft="@dimen/ui_min_element_margin">

        <TextView
            style="@style/HUDFont"
            android:id="@+id/textViewCurrentDistance"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:text="25 Km"
            android:clickable="false"
            android:layout_gravity="center_vertical"
            android:gravity="center_vertical" />
    </view>


</RelativeLayout>
+4
source share
2

:

, ( , ):

view.setLayerType(View.LAYER_TYPE_HARDWARE,null);
//And then apply the animation
view.startAnimation(myAnimation);

:

android:hardwareAccelerated="true"
+11

. Animator .

ObjectAnimator floatingButtonAnimator = ObjectAnimator.ofFloat(floatingActionButton,
ANIMATION_NAME, ANIMATION_STARTING_DEGREE, ANIMATION_ENDING_DEGREE);
floatingButtonAnimator.setDuration(ANIMATION_DURATION).addListener(new AnimatorListenerAdapter() {
  @Override
  public void onAnimationStart(Animator animation) {
    super.onAnimationStart(animation);
  }

  @Override
  public void onAnimationEnd(Animator animation) {
    super.onAnimationEnd(animation);
    exchangeValues();
  }
});
floatingButtonAnimator.start();
-1

Source: https://habr.com/ru/post/1537340/


All Articles