[英]Best way to implement custom view with animation at the center of the screen?
我的目標是在我的應用程序中實現自定義吐司,如下所示:
MyCustomToastClass.makeText(context,View,anyDurationInMS);
我想設置“吐司”重力,布局,持續時間(而不僅僅是Length.SHORT / LONG)
到目前為止我嘗試過的事情:
帶有windowManager對象的類問題是必須在以下位置實現android系統動畫:
params.windowAnimations
當我嘗試實現自定義動畫時,如下所示:
windowManager.addView(mLayout);
Animation AlphaAnimation = new ...
它沒有實現我的動畫。
如果有人實現了此功能,我將不勝感激;或者,如果我以一種方式缺少某些東西,可以為我提供指導。
謝謝
抱歉誤會您的問題
如果您想創建一個像吐司這樣的彈出窗口,並且持續時間由您決定,那么您可以嘗試創建一個自定義視圖,該視圖將包含您要烘烤的內容,然后可以將主布局放置在框架布局中,用戶觸發您的自定義祝酒,您可以將自定義視圖添加到框架布局中,以便將其放置在主布局的前面,並且對於淡入淡出動畫,可以使用此視圖
Animation fadeIn = new AlphaAnimation(0, 1);
fadeIn.setInterpolator(new DecelerateInterpolator()); //add this
fadeIn.setDuration(1000);
Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator()); //and this
fadeOut.setStartOffset(1000);
fadeOut.setDuration(1000);
或者如果您想使用XML
淡入
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0.0"
android:toAlpha= 1.0"
android:duration="1000"
android:repeatCount="infinite"
android:repeatMode="reverse"
/>
淡出
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="1000"
android:repeatCount="infinite"
android:repeatMode="reverse"
/>
而且你可以使用的時間
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// FADE OUT THE POP UP/TOAST HERE
}
}, /*SET THE TIME HERE*/);
我希望這個答案對您來說足夠清楚,如果您對我的答案還有疑問,請隨時在評論中提問:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.