如何在延迟 android 后显示按钮文本
How to display Button text after a delay in android
我创建了新的自定义 Button
class,我想实现,每当用户转到任何 activity 我的通用按钮都想从圆形扩展到默认宽度。展开时我想隐藏按钮文本一段时间,直到按钮动画完成。
请检查我下面的代码:
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);
}
您可以使用 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);
}
轻松通过
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。
我创建了新的自定义 Button
class,我想实现,每当用户转到任何 activity 我的通用按钮都想从圆形扩展到默认宽度。展开时我想隐藏按钮文本一段时间,直到按钮动画完成。
请检查我下面的代码:
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);
}
您可以使用 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);
}
轻松通过
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。