在DialogFragment上方看不到PopupWindow

时间:2019-03-10 10:10:24

标签: android android-dialogfragment popupwindow

有一个具有以下布局结构的DialogFragment:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>

    <variable
        name="vm"
        type="io.evalon.scene.intro.check.permission.PermissionPopupVm" />
</data>

<androidx.cardview.widget.CardView
    android:layout_width="500dp"
    android:layout_height="500dp"
    android:background="#00000000"
    app:cardBackgroundColor="#fff"
    app:cardCornerRadius="10dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="10dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:src="@drawable/permission_title"
                android:tint="@color/success_green"
                android:visibility="invisible" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center_vertical"
                android:text="Title"
                android:textAppearance="@style/TitleText"
                android:textColor="#000"
                android:textSize="30dp" />
        </LinearLayout>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Text"
            android:textColor="#000" />

        <androidx.recyclerview.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:adapter="@{vm.adapter}"
            android:orientation="vertical"
            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
    </LinearLayout>
</androidx.cardview.widget.CardView>
</layout>

enter image description here

当按下此DialogFragment的信息按钮时,会显示PopupWindow。

    fun showPermissionDetailInfo(anchorView: View) {
    //anchorView = infoButton
    val popup = PopupWindow(anchorView.context)
    val view = LayoutInflater.from(anchorView.context)
        .inflate(R.layout.popup_permission_info, null, false)
    popup.contentView = view
    popup.isFocusable = true
    popup.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
    view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
    val xOffset = -(view.measuredWidth - anchorView.width)
    popup.showAsDropDown(anchorView, xOffset + 20, -50)

    }

当我单击索引1中的“信息”按钮时,PopUpWindow会正常显示。

enter image description here

但是当我单击索引2中的“信息”按钮时,从不显示PopupWindow。

我希望这种情况会发生,因为PopupWindow是在父窗口的外部创建的,但是我认为有一种解决方法。

我该如何解决我的问题?

0 个答案:

没有答案