【发布时间】:2016-11-01 09:25:39
【问题描述】:
这是我的 XML 的基本模型:
<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:id="@+id/background_colour"
>
<android.support.design.widget.AppBarLayout
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:id="@+id/profile_screen_appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true"
android:minHeight="150dp"
>
<android.support.design.widget.CollapsingToolbarLayout
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
android:id="@+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:expandedTitleMarginTop="32dp"
app:expandedTitleMarginBottom="32dp"
app:expandedTitleMarginEnd="4dp"
app:expandedTitleMarginStart="32dp"
android:minHeight="100dp"
>
<android.support.v7.widget.Toolbar
android:minHeight="100dp"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:background="@color/fab_material_red_500"
>
</android.support.v7.widget.Toolbar>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blue"
>
<!-- the ViewPager is programatically set to be have the height and width equivalent to that of the screen width of the device --> <com.example.heavymagikhq.MyViewPager
android:padding="0dp"
android:fitsSystemWindows="true"
android:id="@+id/viewPager"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_scrollFlags="scroll|enterAlways"/>
/>
</RelativeLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:layout_marginTop="15dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/profile_info_recycler"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</android.support.design.widget.CoordinatorLayout>
问题
目前RecyclerView 中的一些内容稍微不在屏幕上,我可以通过滚动来显示它。问题是虽然只有少量内容在屏幕外,但整个屏幕会向上滚动,直到只有 RecyclerView 的内容显示在屏幕顶部的 CollapsingToolbarLayout 下方,其折叠高度与 Toolbar 的折叠高度相同。我尝试将android:layout_gravity="fill_vertical" 添加到 RecyclerView 但这并没有解决问题
备注
当 CollapsingToolbarLayout 的高度设置为 625dp 时,屏幕根本不会滚动,但是,当我将其设置为 626dp 时,屏幕的内容会滚动,直到 CollapsingToolbarLayout 折叠到工具栏的高度,所以这额外的 1dp高度使屏幕从不滚动变为滚动超过 1dp。 625dp 的数字可能与设备(Nexus 7 2013)的屏幕尺寸有关。此外,无论minHeight 我将 CollapsingToolbarLayout 设置为什么,CollapsingToolbarLayout 总是在与工具栏相同的高度折叠。
简而言之我的问题
如何才能使屏幕仅滚动以显示不在屏幕上/超出 RecyclerView 内容的内容?
提前致谢。
【问题讨论】:
-
您找到解决方案了吗?我也有同样的问题:(
标签: java android android-recyclerview android-coordinatorlayout android-collapsingtoolbarlayout