【问题标题】:Popup window with recycler view background not working带有回收站视图背景的弹出窗口不起作用
【发布时间】:2020-04-28 01:36:33
【问题描述】:

我想在菜单中显示带有 Recycler 视图的弹出窗口。

弹出窗口右上角 -> 我正在显示向上箭头图标。

所以我为弹出窗口设置了透明背景,并以白色背景显示回收站视图。

`menu.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));`


<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/rvCategory"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical"
    android:elevation="10dp"
    android:background="@drawable/popup_bg"/>

高程不适用于回收站视图。它看起来不像没有边框和高度的菜单。 popup

请帮我解决这个问题。

【问题讨论】:

    标签: android android-layout android-recyclerview android-popupwindow


    【解决方案1】:

    要获得您想要的外观,您可以像这样修改弹出视图 xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    
        <androidx.cardview.widget.CardView xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/cardView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="20dp"
            android:layout_marginBottom="10dp"
            app:cardCornerRadius="6dp"
            app:cardElevation="6dp">
    
            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/rvCategory"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:paddingStart="10dp"
                android:paddingTop="5dp"
                android:paddingEnd="1dp"
                android:paddingBottom="5dp"
                android:clipToPadding="false"
                android:scrollbars="vertical" />
        </androidx.cardview.widget.CardView>
    </LinearLayout>
    

    在您初始化弹出窗口的代码中,它应该是这样的(这里 mContext 是您的活动):

    PopupWindow mPopup = new PopupWindow(mContext);
    View popUpView = mContext.getLayoutInflater().inflate(R.layout.your_popup_xml, null);
    // other initializations
    mPopup.setBackgroundDrawable(null);
    mPopup.setContentView(popUpView);
    mPopup.setFocusable(true);
    mPopup.setClippingEnabled(true);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-26
      • 2016-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多