在滚动RecyclerView

时间:2017-03-08 15:07:34

标签: android android-recyclerview

我正在开发一个原生的Android应用程序,有一些我想做的但不知道如何。我的Recyclerview上方有一个可以滚动的布局,当我滚动recyclelerview或布局本身时,我想让它上升,直到recyclerview(高度为wrap的内容)完全占据屏幕。

我尝试了以下内容:

  • 在NestedScrollView上添加上述内容并添加 app:layout_behavior="@string/appbar_scrolling_view_behavior"来 RecyclerView 这不起作用,recyclerview不会扩展以占据上述布局。每个人都有它的初始高度,只需在该区域内滚动。

然后我在

中阅读了带有RecyclerView的NestedScrollView
  • 添加了NestedScrollView中的所有内容,包括recyclerview。这几乎在添加setNestedScrollingEnable(true)之后起作用,但这打破了RecyclerView模式,所有的recyclerview内容都将在开始时加载,而不是在我滚动时。

我添加了一些图像来描述我想要完成的内容,这是我的布局基础:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:orientation="vertical"
        android:gravity="center"
        android:paddingBottom="@dimen/activity_vertical_margin"
        >
        <com.facebook.drawee.view.SimpleDraweeView
            android:id="@id/profilePicture"
            android:layout_width="@dimen/profileCircleHeight"
            android:layout_height="@dimen/profileCircleHeight"
            fresco:roundingBorderWidth="1dp"
            fresco:roundingBorderColor="@color/profileCircleBorder"
            fresco:roundAsCircle="true"
            />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/userName"
            />

        <TextView
            android:text="@string/friends"
            android:layout_marginTop="@dimen/activity_vertical_margin"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/userFriends"
        android:background="@color/cardColor"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
</LinearLayout>

我知道如何实现这一目标?我虽然在顶部使用了一个不同的视图,但它接触过度的东西这很容易并且有一些性能问题因为将来我会在上面的区域有一个水平滚动回收视图。

由于

PS:上面的区域是我在RecyclerView上面调用的所有名称,在示例中,LinearLayout保持图片和textview。此

可以忽略工具栏

Before Scroll

After scroll

0 个答案:

没有答案