Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

android recyclerview show hide item with animation with default animation

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.view.View;

public final class AnimationUtils {

  public static void slideDown(final View view) {
        view.animate()
                .translationY(view.getHeight())
                .alpha(0.f)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        // superfluous restoration
                        view.setVisibility(View.GONE);
                        view.setAlpha(1.f);
                        view.setTranslationY(0.f);
                    }
                });
    }

    public static void slideUp(final View view) {
        view.setVisibility(View.VISIBLE);
        view.setAlpha(0.f);

        if (view.getHeight() > 0) {
            slideUpNow(view);
        } else {
            // wait till height is measured
            view.post(new Runnable() {
                @Override
                public void run() {
                    slideUpNow(view);
                }
            });
        }
    }

    private static void slideUpNow(final View view) {
        view.setTranslationY(view.getHeight());
        view.animate()
                .translationY(0)
                .alpha(1.f)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        view.setVisibility(View.VISIBLE);
                        view.setAlpha(1.f);
                    }
                });
    }

}
Comment

PREVIOUS NEXT
Code Example
Java :: sorting an arraylist 
Java :: java map not null 
Java :: java generate random id 
Java :: euclids algoritm java gcd 
Java :: how to input in java 
Java :: array liste java 
Java :: java insert into arraylist 
Java :: java template string 
Java :: delete ending part of the string java 
Java :: inline arraylist initialization java 
Java :: split every character in string into array java 
Java :: how to end a program in an if statement java 
Java :: share intent android 
Java :: parse string to int java 
Java :: public String toString() { 
Java :: input char java 
Java :: android java xml combo box 
Java :: java arithmetic operators 
Java :: set password visible in android 
Java :: convert base64 to image png without saving 
Java :: kjk;ok 
Java :: java read directory 
Java :: java % 
Java :: string reverse in java 
Java :: sqlite java gradle 
Java :: How to generate all possible IP addresses based on a given set of digits, in Java? 
Java :: java csv line split 
Java :: Java Create a ConcurrentHashMap 
Java :: how to convert a number into a decimal number in java 
Java :: main method 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =