我们怎样才能在Layout里面创建一个带有回收器视图的透明Fragment Layout?

0 人关注

enter image description here 我目前的应用程序有两个片段,在 FragmentA 中我在工具栏中有一个搜索视图,当点击搜索视图时,我必须使用我的框架布局在 fragmentA 的上面显示另一个片段, FragmentB ,透明的视图,这样 FragmentA 中的内容就可以被看成是模糊的。新打开的透明背景的片段必须在回收器视图中显示一些内容。我们怎样才能在布局中实现透明和回收器视图。

布局代码。

<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">
    <LinearLayout
        android:id="@+id/dot_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/drawer_layout"
        android:elevation="50dp"
        android:gravity="center"
        android:orientation="vertical">
<androidx.appcompat.widget.Toolbar 
   xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/tools"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/palate_survey_bg"
    app:ignore="NamespaceTypo"
    local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <androidx.appcompat.widget.SearchView
        android:id="@+id/Advance_search"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="@drawable/filter_search_bar_bg_lyt"
        app:iconifiedByDefault="false"
        app:queryHint="Search">
    </androidx.appcompat.widget.SearchView>
    </androidx.appcompat.widget.Toolbar >
        <FrameLayout
            android:id="@+id/search_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/toolbar">
        </FrameLayout>
    </LinearLayout>
    </androidx.drawerlayout.widget.DrawerLayout
    
4 个评论
Noah
我甚至不能理解你想做什么。也许你想实现的目标有一个直观的表述会更好。
@Noah--我已经添加了一些细节。
@Noah-有什么更新吗?
Noah
我不明白为什么你需要另一个片段B来显示一个RecyclerView。你可以使用一个活动,然后在活动中,你有一个工具条和一个FrameLayout,然后被另一个片段动态替换。然后RecyclerView就可以在这个片段中显示。所以一个片段就可以了。或者有什么特别的原因吗?
android
android-recyclerview
android-blur-effect
I'm Coder
I'm Coder
发布于 2021-10-05
1 个回答
Noah
Noah
发布于 2021-10-06
已采纳
0 人赞同

根据你提供的详细图像。Fragment B是Fragment A的一个子片段。 Fragment A.所以如果你想在SearchView发出点击事件时显示Fragment B,你应该使用Fragment A的 FragmentManager 。通常情况下,每个片段都有一个FragmentManager,可以容纳其他片段的视图和布局。要检索Fragment A的FragmentManager,请使用以下代码。

片段A内。

  Advance_search.setOnClicklistener( v -> {
            getChildFragmentManager()
                  .beginTransaction()
                  .replace(R.id.search_container, new FragmentB())
                  .commit();

然后在Fragment B的onViewCreated()方法中,你现在可以把你想要的RecyclerView膨胀到Fragment B的视图层中。