Start Edit Text Search Animation - Android User Interface

Android examples for User Interface:TextView Animation

Description

Start Edit Text Search Animation

Demo Code


//package com.java2s;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toolbar;

public class Main {
    public static void StartEditTextSearchAnimation(
            final EditText mEditTextSearch) {
        Toolbar toolbar = (Toolbar) mEditTextSearch.getParent();
        final TextView textView = getTitleTextView(toolbar);
        AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
        alphaAnimation.setDuration(300);
        alphaAnimation/*from w  w  w . java 2 s . co  m*/
                .setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        textView.setVisibility(View.GONE);
                        mEditTextSearch.setVisibility(View.VISIBLE);
                        TranslateAnimation translateAnimation = getTranslateX100To0Animation(
                                mEditTextSearch, 300);
                        mEditTextSearch.startAnimation(translateAnimation);
                        mEditTextSearch.requestFocus();
                        //TODO?????
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });
        textView.startAnimation(alphaAnimation);
    }

    private static TextView getTitleTextView(Toolbar toolbar) {
        TextView textView = null;
        for (int i = 0; i < toolbar.getChildCount(); i++) {
            if (toolbar.getChildAt(i).getClass() == TextView.class) {
                textView = (TextView) toolbar.getChildAt(i);
            }
        }
        return textView;
    }

    private static TranslateAnimation getTranslateX100To0Animation(
            View view, long duration) {
        TranslateAnimation animation = new TranslateAnimation(
                Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF,
                0, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0);
        animation.setDuration(duration);
        return animation;
    }
}

Related Tutorials