private PopupWindow mPopupWindow;
private TextView mTvDelete;
private int mPosition;
//item点击
mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
@Override
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
mPosition = position;
showPopDialog(view);
}
});
//弹出删除气泡
private void showPopDialog(View view){
if (null == mPopupWindow){
View popView = LayoutInflater.from(this).inflate(R.layout.layout_long_click_dialog, null);
mTvDelete = popView.findViewById(R.id.tv_delete);
mTvDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO:点击删除进行的操作
deleteMsg(mPosition);
mPopupWindow.dismiss();
}
});
mPopupWindow = new PopupWindow(popView, FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
mPopupWindow.setOutsideTouchable(true);
mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
}
if (mPopupWindow.isShowing()){
mPopupWindow.dismiss();
}
//第一次显示控件的时候宽高会为0
int deleteHeight = mTvDelete.getHeight()==0?145:mTvDelete.getHeight();
int deleteWidth = mTvDelete.getWidth()==0?212:mTvDelete.getWidth();
mPopupWindow.showAsDropDown(view, (view.getWidth()-deleteWidth/2), -view.getHeight()-deleteHeight);
}
layout_long_click_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:id="@+id/tv_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="删除"
android:textColor="@color/white"
android:background="@color/color_main_blue"/>
</FrameLayout>
网友评论