RecyclerView使用(六)结合PopWindow呈现

RecyclerView使用(六)结合PopWindow呈现

PopWindow使用参考:
http://blog.csdn.net/weixin_37577039/article/details/79369614
RecyclerView使用参考:http://blog.csdn.net/weixin_37577039/article/details/78581423


     // 弹出框
    private void popWindow(View view){
        // 设置背景变暗
        mWindow = getWindow();
        WindowManager.LayoutParams params = mWindow.getAttributes();
        params.alpha = 0.7f;
        mWindow.setAttributes(params);
        View productListView = LayoutInflater.from(this).inflate(R.layout.product_list_view, null);
        // ***这一步是关键***
        plRecyclerView =  productListView.findViewById(R.id.recyclerView);
        PopupWindow popWindow = new PopupWindow(productListView, 780, 900);
        popWindow.setOutsideTouchable(true);      //必须设置背景
        popWindow.setBackgroundDrawable(null);
        //相对于父控件的位置(例如正中央Gravity.CENTER,下方Gravity.BOTTOM等),可以设置偏移或无偏移
        popWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
        // ***网络请求获取list数据***
        askInternet3();
        popWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                if(mWindow!=null){
                    WindowManager.LayoutParams params = mWindow.getAttributes();
                    params.alpha = 1.0f;
                    mWindow.setAttributes(params);
                }
            }
        });
    }

剩下的initData和initView则和Activity使用时一样的

    private void initProductListData(){
        pdAdapter = new ProductListAdapter(productNameList,productTypeList,eachPriceList,totalNumberList);
    }

    private void initProductListView(){
        //设置纵向滚动的 即item是横向分布的
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        //设置布局管理器
        plRecyclerView.setLayoutManager(linearLayoutManager);
        //如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
        plRecyclerView.setHasFixedSize(true);
        //设置adapter
        plRecyclerView.setAdapter(pdAdapter);
        plRecyclerView.addItemDecoration(new MyDividerItemDecoration(
                    this, DividerItemDecoration.VERTICAL));
    }

你可能感兴趣的:(android)