Android实现微信弹出框效果

来源:互联网 发布:电脑部分软件乱码 编辑:程序博客网 时间:2024/06/05 20:19

Android实现微信弹出框效果

1.选上图

 

 

2. 是用pupwindow实现,由于是在RecyclerView中显示的,需要测量当前imageButton所在位置 具体实现代码:

  在代码中调用

  ibComment.setOnClickListener(new View.OnClickListener() {    @Override    public void onClick(View view) {        showMore(ibComment);    }});


pupwindow 实现类

private void showMore(View BtnView) {    if (mMorePopupWindow == null) {        LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);        View content = li.inflate(R.layout.comment_layout, null, false);        mMorePopupWindow = new PopupWindow(content, ViewGroup.LayoutParams.WRAP_CONTENT,                ViewGroup.LayoutParams.WRAP_CONTENT);        mMorePopupWindow.setBackgroundDrawable(new BitmapDrawable());        mMorePopupWindow.setOutsideTouchable(true);        mMorePopupWindow.setTouchable(true);        content.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);        mShowMorePopupWindowWidth = content.getMeasuredWidth();        mShowMorePopupWindowHeight = content.getMeasuredHeight();        Log.i(TAG, "showMore: " + mShowMorePopupWindowHeight);        Log.i(TAG, "showMore: " + mShowMorePopupWindowWidth);        View parent = mMorePopupWindow.getContentView();        TextView like = (TextView) parent.findViewById(R.id.tv1);        TextView comment = (TextView) parent.findViewById(R.id.tv2);    }    if (mMorePopupWindow.isShowing()) {        mMorePopupWindow.dismiss();    } else {        int heightMoreBtnView = BtnView.getHeight();        mMorePopupWindow.showAsDropDown(BtnView, -mShowMorePopupWindowWidth,                -(mShowMorePopupWindowHeight + heightMoreBtnView) / 2);    }}






阅读全文
1 0
原创粉丝点击