繁体   English   中英

android中延迟后如何显示按钮文本

[英]How to display Button text after a delay in android

我创建了新的自定义Button类,无论何时用户进行任何活动,我的通用按钮都希望从圆形扩展到默认宽度。 在扩展时,我想隐藏按钮文本一段时间,直到按钮动画完成。

请检查我下面的代码:

 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);
}

轻松地

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

请注意,您必须在XML或创建视图中将fiButton alpha设置为零android:alpha="0.0"

这条线将在500毫秒后的700毫秒内使您的视图从0变为1。

您可以使用AnimationListener 完成动画后,应在TextView上执行setText

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);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM