【问题标题】:Recyclerview in Nestedscrollview hides last item when getting back from fragmentNestedscrollview 中的 Recyclerview 从片段返回时隐藏最后一项
【发布时间】:2017-08-03 11:25:40
【问题描述】:

我只是需要一些提示。我有片段 A 和片段 B。

片段 A --> 片段 B

在第一次启动时,Fragment A 的布局很好(图 1:第一个屏幕初始 /2。滚动时的第一个屏幕)。但是在转到 Fragment B 并返回 Fragment A 之后。recyclerview 中的最后一项在屏幕下方约 60 dp,如图 3 所示。我在 NestedScrollView 添加了 marginBottom (60dp),并且可以在返回时看到最后一项。但它在 Fragment 首次发布时提供了利润。

我认为 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>

【问题讨论】:

  • 你应该包括你的布局图片和你预期的布局。
  • 我认为你不需要 NestedScrollView,因为它只是包装了 Recyclerview。我认为,即使是根 FrameLayout 也不需要。您可以在 CoordinatorLayout 本身内拥有 FAB。你能把它们去掉并检查吗?

标签: android android-fragments android-recyclerview nestedscrollview


【解决方案1】:

添加类文件

mRecyclerview.setNestedScrollingEnabled(true);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-29
    • 1970-01-01
    • 2021-12-25
    • 1970-01-01
    相关资源
    最近更新 更多