【发布时间】:2017-06-20 09:17:48
【问题描述】:
我在第一次启动片段时遇到了问题。似乎 CoordinatorLayout 为 NestedScrollView 添加了一个负边距,该边距等于 CollapsingToolbarLayout 在折叠状态下的高度(我通过更改高度值对其进行了测试)。因此,位于 NestedScrollView 中的 RecyclerView 无法向上滚动以显示其底部的一些项目。
关于 SO 有一些类似的问题(如 this、this 和 this),但他们没有提供适合我的解决方案,而且他们没有给出任何解释可能会导致问题。
一个有趣的注意事项是,如果我旋转或关闭屏幕然后再打开它会重建布局,然后它会正确显示。另外,如果我点击一个项目,它会触发一些东西,这样我就可以滚动那些隐藏的项目。作为一种解决方法,最好调用一个手动正确重建布局的函数,但我无法弄清楚它是什么(请参阅下面我尝试执行的操作)
我想做什么:
将等于工具栏高度的底部边距添加到 NestedScrollView。虽然它在第一次启动时有所帮助,但在我单击某个项目或旋转屏幕后,额外的边距会将视图从屏幕底部向上推。
调试时我的代码没有发现任何问题。
调用 getView.invalidate() 也没有帮助。
有人可以帮我找出导致问题的原因吗?
fragment_player.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:fitsSystemWindows="true"
tools:context="ru.orgin.glagol.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
android:stateListAnimator="@animator/appbar_always_elevated">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:titleEnabled="false">
<include layout="@layout/player_view"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/player_toolbar_height"
app:layout_collapseMode="none"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >
<ViewAnimator
android:id="@+id/viewAnimator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inAnimation="@android:anim/fade_in"
android:outAnimation="@android:anim/fade_out">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="64dp"
android:layout_gravity="center"
style="?android:attr/progressBarStyle"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:nestedScrollingEnabled="false"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
android:layout_width="match_parent"
android:layout_height="64dp"
android:gravity="center"
android:layout_gravity="center"
android:text="@string/empty_history_books" />
<TextView
android:layout_width="match_parent"
android:layout_height="64dp"
android:gravity="center"
android:layout_gravity="center"
android:text="@string/error_loading_data" />
</ViewAnimator>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
更新:
仍然不知道原因,但似乎将minHeight 属性添加到CollapsingToolbarLayout 就可以了。
【问题讨论】:
标签: android