Files
Android-WaterProject/app/src/main/java/com/ckkj/water/utils/ViewShowOrHideAnimate.java
fengjignqi 1b1575eb8a first
2026-05-16 16:19:39 +08:00

56 lines
1.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.ckkj.water.utils;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
/**
* @Description TODO
* @systemUser 86133
* @Author FengJingQi
* @Date 04-18-2025 周五 11:12
*/
public class ViewShowOrHideAnimate {
public static void showOptionsLayout(View view) {
if (view.getHeight() == 0) {
// View还没测量好post到下一帧去执行
view.post(new Runnable() {
@Override
public void run() {
startShowAnim(view);
}
});
} else {
startShowAnim(view);
}
}
public static void startShowAnim(View view) {
view.setVisibility(View.VISIBLE);
view.setAlpha(0f);
view.setTranslationY(100); // 100px下移初始
view.animate()
.translationY(0)
.setDuration(300)
.setInterpolator(new DecelerateInterpolator()) // 出现时慢慢减速
.start();
}
public static void hideOptionsLayout(View view) {
view.animate()
.translationY(100) // 往下移
.setDuration(300)
.setInterpolator(new AccelerateInterpolator()) // 消失时加速离开
.withEndAction(new Runnable() {
@Override
public void run() {
view.setVisibility(View.GONE);
}
})
.start();
}
}