我想用过渡动画为EditText设置动画。完成动画后,提示不会显示,但是当我调用edittext.requestLayout或当用户专注于edittext时,会出现提示。 requestLayout 听起来像是一个真正的解决方案?
final EditText text = (EditText) findViewById(R.id.editText);
AutoTransition autoTransition = new AutoTransition();
TransitionSet transitionSet = new TransitionSet();
transitionSet.addTransition(autoTransition);
transitionSet.setDuration(2000);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) text.getLayoutParams();
params.width = 0;
params.height = 0;
text.setLayoutParams(params);
transitionSet.addListener(new Transition.TransitionListener() {
@Override
public void onTransitionStart(@NonNull Transition transition) {
}
@Override
public void onTransitionEnd(@NonNull Transition transition) {
AutoTransition autoTransition = new AutoTransition();
TransitionSet transitionSet = new TransitionSet();
transitionSet.addTransition(autoTransition);
transitionSet.setDuration(2000);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) text.getLayoutParams();
params.width = -2;
params.height = -2;
text.setLayoutParams(params);
TransitionManager.beginDelayedTransition((ViewGroup) text.getParent(), transitionSet);
}
@Override
public void onTransitionCancel(@NonNull Transition transition) {
}
@Override
public void onTransitionPause(@NonNull Transition transition) {
}
@Override
public void onTransitionResume(@NonNull Transition transition) {
}
});
TransitionManager.beginDelayedTransition((ViewGroup) text.getParent(), transitionSet);
}