簡體   English   中英

RecyclerView的最后一項被切斷on片段的恢復

[英]RecyclerView last item is cut off onResume of fragment

問題

RecyclerView可以正常運行,並且在不打開detailFragment時也不會剪切視圖。 但它切斷我的最后一個項目RecylerView項目每當我回從后面detailFragment由發起recylcerview項目。

我只在api 26模擬器上遇到此問題。 當我在api 28手機中運行它時,它可以正常工作。 但是我想我可能會丟失一些東西。

fragment_main

<?xml version="1.0" encoding="utf-8"?>
    <androidx.coordinatorlayout.widget.CoordinatorLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:background="@color/colorWhite">

        <com.google.android.material.appbar.AppBarLayout
                android:id="@+id/fragment_main_abl"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:elevation="0dp"
                android:background="@color/colorWhite"
                android:fitsSystemWindows="true">

            <com.google.android.material.appbar.CollapsingToolbarLayout
                    android:id="@+id/fragment_main_ctbl"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed"
                    app:contentScrim="@android:color/white"
                    app:expandedTitleTextAppearance="@color/colorPrimaryText"
                    android:fitsSystemWindows="true">

                <include layout="@layout/header_fragment_main"
                         app:layout_collapseMode="parallax"/>

                <androidx.appcompat.widget.Toolbar
                        android:id="@+id/fragment_main_tb"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        app:layout_collapseMode="pin">
                </androidx.appcompat.widget.Toolbar>

            </com.google.android.material.appbar.CollapsingToolbarLayout>

            <com.google.android.material.tabs.TabLayout
                    android:id="@+id/fragment_main_tl"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/fragment_main_tl_height"
                    app:tabMode="scrollable"
                    app:tabSelectedTextColor="@color/colorPrimary"
                    app:tabTextColor="@color/colorUnselected"/>

        </com.google.android.material.appbar.AppBarLayout>


        <androidx.viewpager.widget.ViewPager
                android:id="@+id/fragment_main_vp"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
             app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"/>

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

fragment_child

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:background="@android:color/white"
        >

    <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/fragment_child_rv"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:clipToPadding="false"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

注意

  • 我不希望為我的recyclerView放置底部填充。 我已經嘗試過了並且可以正常工作,但是在我的recyclerView正常運行的時候,底部會出現多余的填充
  • 我希望盡量nestedScrollView在我的recyclerView使用nestedScrollView ,因為我希望盡可能多地recyclerView

更換

app:layout_scrollFlags="scroll|exitUntilCollapsed"

app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed" 

解決了我的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM