Nestedscrollview中的Recyclerview在从片段返回时隐藏最后一项

时间:2017-08-03 11:25:41

标签: android android-fragments android-recyclerview nestedscrollview

我只需要一些暗示。我有片段A&片段B.

片段A - >片段B

首次启动时,片段A的布局很好(图1:第一个屏幕初始/ 2。滚动时的第一个屏幕)。但是在去片段B后,&返回到片段A. recyclerview中的最后一项在屏幕下方大约60 dp,如图3所示。我在NestedScrollView上添加了marginBottom(60dp),可以看到返回的最后一项。但它首次发布碎片时给出了保证金。

我认为CoOrdinatorLayout和NestedScrollView存在问题,但无法解决此问题。

片段A的布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.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.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

       <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorPrimary">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_collapseMode="parallax"
                android:layout_marginTop="50dp"
                android:layout_marginBottom="50dp"
                android:orientation="vertical"
                >
                <de.hdodenhof.circleimageview.CircleImageView
                    xmlns:app="http://schemas.android.com/apk/res-auto"
                    android:id="@+id/imageView_ProfilePicture"
                    android:layout_width="80dp"
                    android:layout_height="80dp"
                    android:src="@drawable/profile_picture"
                    android:layout_gravity="center_horizontal"
                    android:scaleType="centerCrop"
                    app:layout_collapseParallaxMultiplier="0.7"
                    />

                <Button
                    android:id="@+id/button_Login"
                    style="@style/Base.TextAppearance.AppCompat.Medium"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="10dp"
                    android:layout_marginBottom="5dp"
                    android:paddingLeft="5dp"
                    android:paddingRight="5dp"
                    android:layout_weight="0.10"
                    android:background="@drawable/rectangular_button"
                    android:text="@string/form_btn_login"
                    android:textAllCaps="true"
                    android:textColor="@color/white"/>

                <TextView
                    android:id="@+id/textView_Username"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:textColor="@color/home_username_color"
                    android:textSize="26dp"
                    />

                <TextView
                    android:id="@+id/textView_NumberOfProduct"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:textColor="@color/home_product_no_color"
                    android:textSize="24dp"
                    />
            </LinearLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbarHome"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin" >

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <ImageView
                        android:id="@+id/imageViewDrawerMenu"
                        android:layout_width="46dp"
                        android:layout_height="46dp"
                        android:layout_alignParentLeft="true"
                        android:layout_centerVertical="true"
                        android:src="@drawable/ic_menu"
                        android:padding="8dp"/>
                </RelativeLayout>
            </android.support.v7.widget.Toolbar>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerViewHome"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:overScrollMode="never"/>
    </android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>


<com.github.clans.fab.FloatingActionButton
    android:id="@+id/fab_Scan"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right"
    android:layout_marginBottom="8dp"
    android:layout_marginRight="8dp"
    android:src="@drawable/ic_plus"
    fab:fab_colorNormal="@color/app_primary"
    fab:fab_colorPressed="@color/app_primary_dark"
    fab:fab_colorRipple="@color/app_primary_dark"/>
</FrameLayout>

First screen

Same first screen scrolled up, the last item is showing perfectly

After coming back from another fragment

1 个答案:

答案 0 :(得分:-1)

在课程文件上添加

mRecyclerview.setNestedScrollingEnabled(true);