//recyclerView适配器里写popwindow
//按钮的点击事件
holder.mZan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
View view = LayoutInflater.from(context).inflate(R.layout.pop, null);
window = new PopupWindow(view, 300, ViewGroup.LayoutParams.WRAP_CONTENT );
mDianZan = view.findViewById(R.id.mDianZan);
mPinlun = view.findViewById(R.id.mPinlun);
//点击小赞
mDianZan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
window.dismiss();
}
});
int[] location = new int[2];
v.getLocationOnScreen(location);
//popupWindow.setBackgroundDrawable(new ColorDrawable());
window.setOutsideTouchable(true);
window.setFocusable(false);
//这个弹出的popwindow的位置位于当前点击事件的左边
window.showAtLocation(v, Gravity.NO_GRAVITY, location[0]+v.getWidth()-450, location[1]);
}
});
}
//popwindow 的xml布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:background="@android:color/black"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="50dp">
<TextView
android:id="@+id/mDianZan"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:gravity="center"
android:textStyle="bold"
android:text="赞"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
<TextView
android:id="@+id/mPinlun"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:gravity="center"
android:textStyle="bold"
android:text="评论"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
</LinearLayout>
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/118375.html