diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java index ef93c0dbef123de6e3271ab9e4b2c90944ec89e0..6255cce6915d5c48c579932a3b214bf39be17c23 100644 --- a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java +++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java @@ -8,6 +8,7 @@ import com.kunzisoft.switchdatetime.time.RadialPickerLayout; import com.kunzisoft.switchdatetime.time.SwitchTimePicker; import ohos.aafwk.ability.Ability; import ohos.agp.animation.Animator; +import ohos.agp.animation.AnimatorGroup; import ohos.agp.animation.AnimatorProperty; import ohos.agp.colors.RgbColor; import ohos.agp.components.*; @@ -94,6 +95,7 @@ public class SwitchDateTimeDialogFragment extends CommonDialog { * 当前系统语言是否是中文 */ private boolean isLaChina = true; + private AnimatorGroup animatorGroup; private SwitchDateTimeDialogFragment(Context context) { super(context); @@ -535,12 +537,75 @@ public class SwitchDateTimeDialogFragment extends CommonDialog { default: break; } - text_month.setText(s); +// text_month.setText(s); + setTextMonthAnimator(s); MessageEvent.month = mon; System.out.println("-->>setMonth.MessageEvent.month= "+MessageEvent.month); MessageEvent.year = String.valueOf(year); } + private void setTextMonthAnimator(String s){ + if (!text_month.getText().isEmpty() &&!text_month.getText().equals(s)){ + + if (animatorGroup != null && animatorGroup.isRunning()){ + text_month.setText(s); + text_month.setAlpha(1.0f); + return; + } + // 创建动画组对象 + animatorGroup = new AnimatorGroup(); + // 动画1 + AnimatorProperty action1 = new AnimatorProperty(); + action1.setTarget(text_month); + action1.moveFromY(0).moveByY(-200).setDuration(100); + action1.setStateChangedListener(new Animator.StateChangedListener() { + @Override + public void onStart(Animator animator) { + + } + + @Override + public void onStop(Animator animator) { + + } + + @Override + public void onCancel(Animator animator) { + + } + + @Override + public void onEnd(Animator animator) { + text_month.setText(s); + text_month.setAlpha(0); + } + + @Override + public void onPause(Animator animator) { + + } + + @Override + public void onResume(Animator animator) { + + } + }); + // 动画2 + AnimatorProperty action2 = new AnimatorProperty(); + action2.setTarget(text_month); + action2.moveFromY(0).moveByY(400).setDuration(50); + // 动画3 + AnimatorProperty action3 = new AnimatorProperty(); + action3.setTarget(text_month); + action3.moveFromY(0).moveByY(-200).alpha(1.0f).setDuration(100); + // 先动画1后动画2 + animatorGroup.runSerially(action1, action2, action3); + animatorGroup.start(); + } else { + text_month.setText(s); + } + } + /** * onMessageEvent *