Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown animation name: decelerateInterpolator

Android Studio 1.5
Device Samsung 4.4.2

I am trying to animate items loaded from a ArrayList into a recyclerview. I when the dropdown arrow is clicked the items should animate (decelerate) when expanded and should animate when collapsed. However, currently the list items just appears.

Code that calls the setAnimation

 @Override
    public void onBindChildViewHolder(ChatChildViewHolder childViewHolder, int position, Object childListItem) {
        ChatChildTitles chatChildTitles = (ChatChildTitles)childListItem;
        childViewHolder.tvChildTitle.setText(chatChildTitles.getTitle());

        setAnimation(childViewHolder.cvChildRooms, position);
    }

Code for setting the animation

  private void setAnimation(CardView viewToAnimate, int position) {
        Animation animation = AnimationUtils.loadAnimation(mContext, android.R.anim.fade_in);
        animation.setInterpolator(mContext, android.R.anim.decelerate_interpolator);
        viewToAnimate.startAnimation(animation);
    }

Here is a couple of screenshots:

In the collapsed state

enter image description here

After the arrow has been clicked expland the list enter image description here

This is my layout I am using that represents the rows that will be displayed in the recyclerView:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    android:id="@+id/cvChildRooms"
    xmlns:card="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    card:cardBackgroundColor="@color/child_header_lighter_grey"
    card:contentPadding="4dp"
    card:cardPreventCornerOverlap="true">

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/profile_image"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_gravity="center_vertical|start"
        android:src="@drawable/photorace"/>

    <TextView
        android:id="@+id/tvChildTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center"
        android:text="Coffee Latte Room"
        android:fontFamily="sans-serif-light"
        android:textSize="16sp"
        android:textColor="@android:color/black"/>
</android.support.v7.widget.CardView>

I have a function that should start the animation.

private void setAnimation(CardView viewToAnimate, int position) {
    Animation animation = AnimationUtils.loadAnimation(mContext, android.R.anim.decelerate_interpolator);
    viewToAnimate.startAnimation(animation);
}

I have tested using the following that works ok with slide_in_left. However, I don't want them to slide in from the left

Animation animation = AnimationUtils.loadAnimation(mContext, android.R.anim.slide_in_left);
viewToAnimate.startAnimation(animation);

Many thanks for any suggestions,

like image 584
ant2009 Avatar asked Oct 28 '15 09:10

ant2009


People also ask

What is DecelerateInterpolator?

android.view.animation.DecelerateInterpolator. An interpolator where the rate of change starts out quickly and and then decelerates.

What is Tweened animation in Android?

Tween Animation takes some parameters such as start value , end value, size , time duration , rotation angle e.t.c and perform the required animation on that object. It can be applied to any type of object. So in order to use this , android has provided us a class called Animation.

What are the two different types of view animation?

There are two types of animations that you can do with the view animation framework: Tween animation: Creates an animation by performing a series of transformations on a single image with an Animation. Frame animation: or creates an animation by showing a sequence of images in order with an AnimationDrawable .


2 Answers

If you want to use a decelerate interpolator you need to set it AS an interpolator, not as the animator:

private void setAnimation(CardView viewToAnimate, int position) {
    Animation animation = AnimationUtils.loadAnimation(mContext, android.R.anim.fade_in); //change this with your desidered (or custom) animation
    animation.setInterpolator(mContext, android.R.anim.decelerate_interpolator);
    viewToAnimate.startAnimation(animation);
}

UPDATE

You said that you are using com.bignerdranch.android:expandablerecyclerview:2.0.3.

From the official docs of the library, it's clearly state how to create expand/collapse animations:

You can also create your own animations for expansion by overriding ParentViewHolder#onExpansionToggled(boolean), which will be called for you when the itemView is expanded or collapsed.

I suggest you to take a look at the official example of the library.

like image 92
bonnyz Avatar answered Oct 06 '22 22:10

bonnyz


You can't use decelerate_interpolator because it's not an animation, it is an interpolator:

An interpolator defines the rate of change of an animation. This allows the basic animation effects (alpha, scale, translate, rotate) to be accelerated, decelerated, repeated, etc.

Reference:
http://developer.android.com/reference/android/view/animation/Interpolator.html

As you can see the XML that describing them are completely different:

Source of decelerate_interpolator.xml:

<decelerateInterpolator />

Source of slide_in_left.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="-50%p" android:toXDelta="0"
            android:duration="@android:integer/config_mediumAnimTime"/>
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0"
            android:duration="@android:integer/config_mediumAnimTime" />
</set>
like image 30
Mattia Maestrini Avatar answered Oct 07 '22 00:10

Mattia Maestrini