PopupWindow 一般商城都用得到 有综合排序

效果图:

PopupWindow的知识点

//方法一: 
public PopupWindow (Context context) 
//方法二:  
public PopupWindow(View contentView)  
//方法三:  
public PopupWindow(View contentView, int width, int height)  
//方法四:  
public PopupWindow(View contentView, int width, int height, boolean focusable) 

showAsDropDown(view);//相对某个控件的位置(正左下方),无偏移 

showAtLocation(contentView,Gravity.BOTTOM,0,0); //相对于父控件的位置(例如正中央Gravity.CENTER,下方Gravity.BOTTOM等),可以设置偏移或无偏移

setOutsideTouchable(true);//点击popupwindow外部消失

setFocusable(true);//获取焦点

setOnDismissListener(this);//加上上面两句让popupwindow自动消失

setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_pupwindow));// 如果不设置PopupWindow的背景,无论是点击外部区域还是Back键都无法dismiss弹框

 mPopuoWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                //pop消失的时候的监听
                mSupplierListTvProduct.setTextColor(Color.parseColor("#5a5959"));
                mSupplierListTvSort.setTextColor(Color.parseColor("#5a5959"));
                mSupplierListTvActivity.setTextColor(Color.parseColor("#5a5959"));
            }
        });

popupWindow消失时的监听,消失时取消按钮的选中的状态

 public void onClick(View view) {
        switch (view.getId()){
            case R.id.around_supplier_list_product:
                mSupplierListTvProduct.setTextColor(Color.parseColor("#39ac69"));
                mPopListView.setAdapter(mMenuAdapter1);
                mPopuoWindow.showAsDropDown(mSupploerListProduct, 0, 2);
                supplierMenuIndex = 0;
                break;
            case R.id.around_supplier_list_sort:
                mSupplierListTvSort.setTextColor(Color.parseColor("#39ac69"));
                mPopListView.setAdapter(mMenuAdapter2);
                mPopuoWindow.showAsDropDown(mSupplierListSort, 0, 2);
                supplierMenuIndex = 1;
                break;
            case R.id.around_supplier_list_activity:
                mSupplierListTvActivity.setTextColor(Color.parseColor("#39ac69"));
                mPopListView.setAdapter(mMenuAdapter3);
                mPopuoWindow.showAsDropDown(mSupplierListActivity, 0, 2);
                supplierMenuIndex = 2;
                break;
            default:
                break;
        }
    }

使用supplierMenuIndex来标记点击的种类,在ListView.setOnItemClickListener的时候可以分出点击哪一个里面的内容

mPopListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                switch (supplierMenuIndex){
                    case 0:
                        mSupplierListTvProduct.setText(mMenuData1.get(i).get("name"));
                        mPopuoWindow.dismiss();
                        break;
                    case 1:
                        mSupplierListTvSort.setText(mMenuData2.get(i).get("name"));
                        mPopuoWindow.dismiss();
                        break;
                    case 2:
                        mSupplierListTvActivity.setText(mMenuData3.get(i).get("name"));
                        mPopuoWindow.dismiss();
                        break;
                    default:
                        break;
                }
            }
        });



   <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="1px"
        android:orientation="horizontal">
        <View
            android:id="@+id/pop_location_view_product"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"/>
        <View
            android:id="@+id/pop_location_view_sort"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            />
        <View
            android:id="@+id/pop_location_view_activity"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            />
    </LinearLayout>

这样可以使3个popupwindow分别在全部,综合排序,优惠活动的正下方

mPopuoWindow.showAsDropDown(popLocationViewProduct);
mPopuoWindow.showAsDropDown(popLocationViewSort);
mPopuoWindow.showAsDropDown(popLocationViewActivity);


代码下载地址:https://download.csdn.net/download/jingerlovexiaojie/10194684

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值