I'm trying to create an animation where there is one layout shown, and when I press it another one fades below it.

because I want to put it in a recyclerView I want the divider to slide down before the second layout showing.

the problem I'm having is that the divider doesn't animate the moving down, it just jumps straight down.

here's my code:

package com.example.itayrabin.layouttest;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
import android.widget.LinearLayout;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class rvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>     implements View.OnClickListener {

private Context mContext;

public rvAdapter(Context context) {
    mContext = context;
}

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    final View view = LayoutInflater.from(mContext).inflate(R.layout.layout,parent,false);
    final TestViewHolder holder = new TestViewHolder(view);
    holder.llContent.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            holder.llExpendedContent.setVisibility(View.INVISIBLE);

            holder.vDivider.animate()
                    .translationY(holder.llExpendedContent.getMeasuredHeight())
                    .setDuration(500)
                    .setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            super.onAnimationEnd(animation);

                            holder.llExpendedContent.setVisibility(View.VISIBLE);
                        }
                    }).start();
        }
    });
    return holder;
}

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
}

@Override
public int getItemCount() {
    return 20;
}

@Override
public void onClick(View v) {
    if (v.getId() == R.id.llContent){

    }
}


public static class TestViewHolder extends RecyclerView.ViewHolder {


    @InjectView(R.id.llExpendedContent)
    LinearLayout llExpendedContent;
    @InjectView(R.id.vDivider)
    View vDivider;
    @InjectView(R.id.llContent)
    LinearLayout llContent;

    public TestViewHolder(View view) {
        super(view);

        ButterKnife.inject(this,view);

    }

}
}

and here's the layout of a single row:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="wrap_content" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:orientation="vertical" android:id="@+id/llContent" android:clickable="true">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:id="@+id/llMainContent"
    android:layout_weight="1">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="Bread(5)"
        android:textColor="@color/abc_primary_text_material_light"
        android:textStyle="bold" />

    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="15.3 Dollars"/>
</LinearLayout>

<LinearLayout
    android:id="@+id/llExpendedContent"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="horizontal"
    android:layout_weight="1"
    android:visibility="gone">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="Milk(10)"
        android:textColor="@color/abc_primary_text_material_light"
        android:textStyle="bold" />

    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="60 Dollars"/>

    </LinearLayout>

<View
    android:id="@+id/vDivider"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="#eeeeee" />

(as you can see I am using ButterKnife for it's ease of use.)

after the duration of the animation the second layout does appear, so Its not like the animation isn't playing or something, its just that it jumps straight down.

Related posts

Recent Viewed