PopupWindow 从底部弹出窗体

第一步  : 初始化PopupWindow

    private void initPop() {

        if (view == null) {
            // 照片
            view = View.inflate(RegisterActivity.this, R.layout.pop_phone, null);   / /加载对象
        }
        if (mPopupWindow == null) {
            mPopupWindow = new PopupWindow(view, LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT, true);
        }

    }

第二步 ,点击事件打开开

    // 打开pop
    private void openPopup() {
        mPopupWindow.setBackgroundDrawable(new ColorDrawable(Color
                .parseColor("#b0000000")));  //设置背景颜色
        mPopupWindow.showAtLocation(register_lay_out, Gravity.BOTTOM, 0, 0);
        mPopupWindow.setAnimationStyle(R.style.app_pop);
        mPopupWindow.setOutsideTouchable(true);   //点击外面关闭
        mPopupWindow.setFocusable(true);    //得到焦点
        mPopupWindow.update();
      }
R.style.app_pop
    <style name="AppTheme" parent="android:Theme.Light" />
        <style name="app_pop">
        <item name="android:windowEnterAnimation">@anim/pop_up</item>
        <item name="android:windowExitAnimation">@anim/pop_down</item>
    </style>
pop_up.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="0"
    android:toXDelta="0"
    android:fromYDelta="100%"
    android:toYDelta="0%"
    android:duration="200">
</translate>
pop_down.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="0"
    android:toXDelta="0"
    android:fromYDelta="0%"
    android:toYDelta="100%"
    android:duration="200">
</translate>

 

附录 :打开前 先判断 关闭

    private void dismissPopupWindow() {
        // 把旧的弹出窗体关闭掉。
        if (mPopupWindow != null && mPopupWindow.isShowing()) {
            mPopupWindow.dismiss();
            // mPopupWindow = null;
        }
    }

 

posted @ 2015-01-13 17:17  每天学习一点点...  阅读(396)  评论(0编辑  收藏  举报