美文网首页
popupWindow的使用

popupWindow的使用

作者: __MX | 来源:发表于2019-09-27 14:09 被阅读0次

    private void initQiandao() {

    View popupview = LayoutInflater.from(this).inflate(R.layout.quandaozmglayout, null);

    popupWindow1 = new PopupWindow(this);

    popupWindow1.setContentView(popupview);

    popupWindow1.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);//自适应高度

    popupWindow1.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);//自适应高度

    popupWindow1.setAnimationStyle(R.style.mypopupstyle);//动画

    popupWindow1.setBackgroundDrawable(new BitmapDrawable());

    popupWindow1.setFocusable(true);

    popupWindow1.showAtLocation(qiandaolayout, Gravity.CENTER, 0, 0);

    bgAlpha(0.5f);//半透明背景

    popupWindow1.setOutsideTouchable(true);

    popupWindow1.setBackgroundDrawable(new ColorDrawable(Color.BLUE));

    popupWindow1.setOnDismissListener(new PopupWindow.OnDismissListener() {

    @Override

    public void onDismiss() {

    bgAlpha(1f);//白色背景

    }

    });

    }

    点击关闭背景还原

    private void bgAlpha(float alpha) {

    WindowManager.LayoutParams lp = (QianDaosmgActivity.this.getWindow()).getAttributes();

    lp.alpha = alpha;// 0.0-1.0

    (QianDaosmgActivity.this.getWindow()).setAttributes(lp);

    }

    动画

    <style name="mypopupstyle">

    <item name="android:windowEnterAnimation">@anim/enter</item>   //进

    name="android:windowExitAnimation">@anim/exit</item>  //出

    @anim/enter

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

        android:fromYDelta="100%p"

        android:toYDelta="0"

        android:duration="500"

        >

    @anim/exit

    rsion="1.0" encoding="utf-8"?>

        android:fromYDelta="0"

        android:toYDelta="100%p"

        android:duration="500"

        >

    相关文章

      网友评论

          本文标题:popupWindow的使用

          本文链接:https://www.haomeiwen.com/subject/cazouctx.html