1. 程式人生 > >PopWindow使用實戰

PopWindow使用實戰

這篇就不講解popWindow因為太早了,我最近在做一個專案的時候正好用到了,下面直接說下使用

private void initPopWinDow() {
        //1.新增pop佈局
        View view = View.inflate(this, R.layout.popwin_item, null);
        /*
         * 2.建立pop物件,並傳入pop佈局
         * 第一個引數:pop佈局
         * 第二個引數:寬,第三個引數:高
         * 第四個引數:是否可以獲得焦點
         * */
        mPopupWindow = new PopupWindow(view, 400, 200, true);

        //設定pop背景
        mPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
        
        /*
        * 顯示pop
        *   第一個引數是顯示在哪個佈局
        *   第二個引數是位置
        *   第三、第四分別是X、Y軸
        * */
        View inflate = View.inflate(this, R.layout.activity_main, null);
        mPopupWindow.showAtLocation(inflate,Gravity.BOTTOM,0,0);
     }