2

I created new custom Button class, I want to achieve, whenever user go to any activity my generic button want to expand from circle to default width. While expanding I want to hide button text for while until button animation complete.

Please check my below code:

 private void animateMe(Context context){
    final String btnText = this.getText().toString();
    final FIButton fiButton = this;
    fiButton.setText("");

    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            fiButton.setText(btnText);
        }

    },500);


    Animation animation = AnimationUtils.loadAnimation(context,
            R.anim.expand);
    super.startAnimation(animation);
}
Haneef Ansari
  • 113
  • 1
  • 3
  • 8

2 Answers2

3

Easily by

ViewCompat.animate(fiButton ).setStartDelay(500).alpha(1).setDuration(700).setInterpolator(new DecelerateInterpolator(1.2f)).start();

note that you have to set the fiButton alpha to zero android:alpha="0.0" in you xml or on create view

this line will animate your view from 0 to 1 in 700 millisecond after 500 millisecond.

AbuQauod
  • 919
  • 14
  • 30
0

You can use an AnimationListener. On finishing the animation you should do setText on the TextView.

private void animateMe(Context context){
    final String btnText = this.getText().toString();
    final FIButton fiButton = this;

    fiButton.setText("");        
    Animation animation = AnimationUtils.loadAnimation(context, R.anim.expand);        
    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            fiButton.setText("");
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            fiButton.setText(btnText);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });
    super.startAnimation(animation);
}
K Neeraj Lal
  • 6,768
  • 3
  • 24
  • 33
  • And i have another issue, as i mentioned i want to transform all the buttons from circle state to wrap_content width.. all my buttons have border radius. when i animate its shows in square. `` – Haneef Ansari Nov 08 '17 at 07:11