【发布时间】:2019-01-14 07:45:53
【问题描述】:
我试图在回收站视图中的特定视图上显示一个弹出窗口,但它没有显示在该位置。
这是我为显示透明弹出窗口所做的:
private void showPopup(View view) {
LayoutInflater inflater = (LayoutInflater) HomeActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View layout = inflater.inflate(R.layout.fadepopup, findViewById(R.id.fadePopup));
PopupWindow fadePopup = new PopupWindow(layout, 300, 500, true);
fadePopup.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, android.R.color.transparent)));
fadePopup.setOutsideTouchable(true);
fadePopup.showAtLocation(view, Gravity.BOTTOM | Gravity.CENTER, 0, 0);
}
我从回收站视图中调用它,例如:
horizontalRecyclerView.addOnItemTouchListener(new RecyclerTouchListener(getApplicationContext(), recyclerView, new RecyclerTouchListener.ClickListener() {
@Override
public void onClick(View view, int position) {
String menuTitle = menuTitles[position % menuTitles.length];
Fragment selectedFragment = null;
switch (menuTitle) {
case "Messenger":
showPopup(view);
break;
}
}
@Override
public void onLongClick(View view, int position) {
}
}));
另外,我尝试了showAsDropDown,但没有工作。
结果是:
更新:
XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fadePopup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/messenger_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/circular_white"
android:padding="10dp"
android:src="@drawable/nav_messanger" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/circular_white"
android:padding="10dp"
android:src="@drawable/nav_contacts" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/circular_white"
android:padding="10dp"
android:src="@drawable/nav_boss" />
</LinearLayout>
【问题讨论】:
标签: android android-popupwindow