Recyclerview с фиксированной высотой не будет прокручиваться во вложенном виде - PullRequest
0 голосов
/ 03 января 2019

У меня есть RecyclerView с фиксированной высотой внутри NestedScrollView с несколькими другими раскладками внутри.Представление переработчика не будет прокручиваться, но оно прокручивается нормально, если я установил его высоту wrap_content

Я не могу заставить RecyclerView использовать wrap_content, потому что есть проблема с EndlessRecyclerViewScrollListener в том, что он продолжает загружать данные с сервера и загружать их в мой Adapter, даже если пользователь не прокрутил внизвообще.

Большинство предлагает установить для вложенной прокрутки значение false, но если я отключу вложенную прокрутку, NestedScrollView не позволит мне прокрутить мой RecyclerView.Но если я оставлю вложенную прокрутку включенной, представление прокрутки не будет прокручиваться, пока я не начну касаться снаружи RecyclerView.

моего кода макета:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/scoop_background"
tools:context=".module.scoop.timeline.ScoopTimelineFragment">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:orientation="vertical">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="92dp">

        <ImageView
            android:id="@+id/ivTimelineBanner"
            android:layout_width="match_parent"
            android:layout_height="92dp"
            android:layout_margin="0dp"
            android:clickable="true"
            android:padding="0dp"
            android:scaleType="fitXY"
            android:src="@drawable/banner_placeholder" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center_vertical"
                android:orientation="vertical"
                android:paddingLeft="92dp">

                <TextView
                    android:id="@+id/tvGroupMembership"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/text_content" />

                <TextView
                    android:id="@+id/tvGroupName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/text_header"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/tvGroupMemberCount"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/text_content" />

            </LinearLayout>

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:background="@null"
                android:paddingStart="@dimen/divider_normal"
                android:paddingEnd="@dimen/divider_normal"
                android:src="@drawable/ic_chevron_right_white_24dp" />

        </LinearLayout>

    </FrameLayout>

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipeRefreshLayoutTimeline"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/nestedScrollView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"
            android:overScrollMode="never"
            android:scrollbars="none">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:paddingTop="4dp">

                <android.support.v7.widget.CardView
                    android:id="@+id/cvCreateScoop"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/divider_small"
                    android:layout_marginRight="@dimen/divider_small"
                    android:clickable="true"
                    android:focusable="true"
                    android:foreground="?attr/selectableItemBackground"
                    app:cardCornerRadius="8dp"
                    app:cardUseCompatPadding="true">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:padding="@dimen/divider_normal">

                        <ImageView
                            android:layout_width="32dp"
                            android:layout_height="32dp"
                            android:src="@drawable/svg_nav_create_scoop" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:gravity="center_vertical"
                            android:paddingStart="@dimen/divider_normal"
                            android:text="What's on your mind?"
                            android:textSize="@dimen/text_content" />

                        <ImageView
                            android:layout_width="32dp"
                            android:layout_height="32dp"
                            android:padding="@dimen/divider_xsmall"
                            android:src="@drawable/svg_insert_image" />
                    </LinearLayout>

                </android.support.v7.widget.CardView>

                <RelativeLayout
                    android:id="@+id/relativeLayout"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/rv"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:clipToPadding="false"
                        android:overScrollMode="never"
                        android:nestedScrollingEnabled="false"
                        android:paddingLeft="8dp"
                        android:paddingRight="8dp"
                        android:paddingBottom="4dp">

                    </android.support.v7.widget.RecyclerView>


                </RelativeLayout>

            </LinearLayout>

        </android.support.v4.widget.NestedScrollView>

    </android.support.v4.widget.SwipeRefreshLayout>

</LinearLayout>

Что мне нужно изменить, чтобы RecyclerView можно было прокручивать, но вместе с ним прокручивалось и целое NestedScrollView, так что, если пользователь прокручивает назад вверх (пролистывая сверху вниз), прокручивается RecyclerViewвместе с NestedScrollView, который принесет макеты выше RecyclerView.

Для визуализации:

Макет, который я пытаюсь достичь, похож на этотиз фейсбука.При прокрутке вниз временная шкала будет прокручиваться вниз, а панель поиска со значком мессенджера вверху также прокручивается, поэтому при прокрутке вниз она скрывается.При прокрутке вверх временная шкала прокручивается назад и снова отображается строка поиска.

1 Ответ

0 голосов
/ 05 января 2019

Я решил сделать это по-другому, потому что я не смог решить это с помощью этого метода.Вместо этого я использовал CollapsingToolbar и поместил в него другие макеты, затем удалил его фон, чтобы он не выглядел как панель инструментов, и он плавно выполняет то, что хотел, только с другой реализацией.

...