popupWindow 快顯視窗時的動畫

來源:互聯網
上載者:User

標籤:


首先,在values/anim中定義補間動畫

popshow_anim.xml 由下往上淡入

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android" >    <translate        android:duration="1000"        android:fromYDelta="100%p"        android:toYDelta="0" />    <alpha        android:duration="1000"        android:fromAlpha="0.0"        android:toAlpha="1.0" /></set>

pophidden_anim.xml 由上往下淡出

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android" >    <translate        android:duration="1000"        android:fromYDelta="0"        android:toYDelta="50%p" />    <alpha        android:duration="1000"        android:fromAlpha="1.0"        android:toAlpha="0.0" /></set>


然後,在values/style中定義樣式

    <style name="mypopwindow_anim_style">

        <item name="android:windowEnterAnimation">@anim/popshow_anim</item> <!-- 指定顯示的動畫xml -->        <item name="android:windowExitAnimation">@anim/pophidden_anim</item> <!-- 指定消失的動畫xml -->    </style>  


最後,在代碼中引用動畫樣式

        View view = LayoutInflater.from(this).inflate(R.layout.popwindowlayout, null);

        PopupWindow mPopupWindow = new PopupWindow(view, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);        mPopupWindow.setFocusable(true);        mPopupWindow.setOutsideTouchable(true);        mPopupWindow.setBackgroundDrawable(new ColorDrawable(0xcc00cc00));        // 設定popWindow的顯示和消失動畫        mPopupWindow.setAnimationStyle(R.style.mypopwindow_anim_style);        mPopupWindow.showAtLocation(MainActivity.this.findViewById(R.id.start), Gravity.BOTTOM, 0, 0);





來自為知筆記(Wiz)

popupWindow 快顯視窗時的動畫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.