Android弹出窗口

protected void PopUp()
    {
        final PopupWindow popup = new PopupWindow(TestActivity.this);

        View popView = LayoutInflater.from(TestActivity.this).inflate(R.layout.activity_show1, null);

        popup.setContentView(popView);

        popup.setFocusable(true);

        DisplayMetrics metric = new DisplayMetrics();

        getWindowManager().getDefaultDisplay().getMetrics(metric);

        int width = metric.widthPixels; // 屏幕宽度(像素)

        int height = metric.heightPixels; // 屏幕高度(像素)

        popup.setWidth(Integer.parseInt(new DecimalFormat("0").format(width * 0.8)));

        popup.setHeight(Integer.parseInt(new DecimalFormat("0").format(height * 0.8)));

        popup.showAtLocation(TestActivity.this.findViewById(R.id.textViewSync), Gravity.CENTER, 0, 0);

        popView.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {

                popup.dismiss();

            }

        });
    }

 

posted @ 2018-10-17 16:08  zhaogaojian  阅读(1391)  评论(0编辑  收藏  举报