【问题标题】:How to display Button text after a delay in android如何在android延迟后显示按钮文本
【发布时间】:2017-11-08 06:50:10
【问题描述】:

我创建了新的自定义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);
}

【问题讨论】:

    标签: java android xml android-studio android-animation


    【解决方案1】:

    轻轻松松

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

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

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

    【讨论】:

    • 我通过 Material Design 找到了另一种实现这种动画效果的方法。
    【解决方案2】:

    您可以使用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);
    }
    

    【讨论】:

    • 我还有另一个问题,正如我提到的,我想将所有按钮从圆形状态转换为 wrap_content 宽度.. 我所有的按钮都有边框半径。当我以正方形为其节目制作动画时。 <scale android:duration="800" android:fromXScale="0.1" android:toXScale="1.0" android:fromYScale=".9" android:toYScale="1.0" android:pivotX="50%" android:pivotY="100%" />
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-27
    • 1970-01-01
    • 2019-10-26
    • 1970-01-01
    • 1970-01-01
    • 2021-11-16
    • 2023-03-25
    相关资源
    最近更新 更多