PopupWindow的基礎使用,popupwindow基礎

來源:互聯網
上載者:User

PopupWindow的基礎使用,popupwindow基礎

轉載請註明出處,謝謝~~

首先,這是一篇工具類部落格,主要是實現PopupWindow從上或下或左右出現的效果。為了不用每次都重寫,所以抽出了一個方法。

private void initPopuptWindow() {        LayoutInflater layoutInflater = LayoutInflater.from(this);        //user_icon替換成你自己的layout        View popupWindow = layoutInflater.inflate(R.layout.user_icon, null);        mPopupWindow = new PopupWindow(popupWindow, LayoutParams.MATCH_PARENT,                LayoutParams.MATCH_PARENT);        mPopupWindow.setOutsideTouchable(true);        mPopupWindow.setFocusable(true);        //這個屬性一定要設定        mPopupWindow.setBackgroundDrawable(new ColorDrawable(-000000));        //這是設定popupwindow出現的動畫        mPopupWindow.setAnimationStyle(R.style.anim_photo_select);        //ll_root是你要依賴哪個控制項出現,這裡是跟布局的控制項id,Gravity是你要從哪裡出來,這裡是底部。然後後兩位是x,y方向的位移量。        mPopupWindow.showAtLocation(ll_root, Gravity.BOTTOM, 0, 0);    }

R.style.anim_photo_select是popupwindow出現的動畫,這是寫在styles.xml檔案裡的:

<style name="anim_photo_select">        <item name="android:windowEnterAnimation">@anim/photo_pop_in</item>        <item name="android:windowExitAnimation">@anim/photo_pop_out</item></style>

然後@anim/photo_pop_in和out是動畫檔案,放在anim檔案夾中。
in:

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <translate android:fromYDelta="100%p" android:toYDelta="0"            android:duration="@android:integer/config_mediumAnimTime"/>    <alpha android:fromAlpha="0.5" android:toAlpha="1.0"            android:duration="@android:integer/config_mediumAnimTime" /></set>

out:

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <translate android:fromYDelta="0%p" android:toYDelta="100%p"        android:duration="@android:integer/config_mediumAnimTime"/>    <alpha android:fromAlpha="1.0" android:toAlpha="0.5"        android:duration="@android:integer/config_mediumAnimTime" /></set>

效果,由於沒做適配,所以湊合著看吧,哈哈哈:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.