Android:仿微信表情预览,popwindow的弹框位置

本文详细介绍了在Android应用中如何仿照微信实现表情预览功能,重点讲解了如何自定义PopWindow并调整其弹出位置和距离,以满足不同场景的需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 private void showWinddowAbove(View view,int dra){
        View contentView = LayoutInflater.from(getActivity()).inflate(
                R.layout.poplay, null);
        if(popupWindow == null){
            popupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
            popupWindow.setFocusable(true);
            popupWindow.setOutsideTouchable(true);
            // 如果不设置PopupWindow的背景,有些版本就会出现一个问题:无论是点击外部区域还是Back键都无法dismiss弹框
            popupWindow.setBackgroundDrawable(getResources().getDrawable(
                    R.drawable.circle_bg));
            face_img = contentView.findViewById(R.id.face_img);
        }

        Glide.with(getActivity()).load(dra).into(face_img);
        int[] location = new int[2];
        view.getLocationOnScreen(location);
         popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, location[0], location[1] - popupWindow.getHeight());
        //在控件的下方弹出窗口
        //popupWindow.showAsDropDown(view);
        //左边
        //popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, location[0] - view.getWidth(), location[1]);
        //右边
        //popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, location[0] + view.getWidth(), location[1]);

    }

我的需求是上面撒,这边可以调整距离以及位置的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值