相关疑难解决方法(0)

CollapsingToolbarLayout 在android中向下推NestedScrollView

我在第一次启动片段时遇到了问题。似乎 CoordinatorLayout 为 NestedScrollView 添加了一个负边距,它等于折叠状态下 CollapsingToolbarLayout 的高度(我通过更改高度的值对其进行了测试)。因此,位于 NestedScrollView 中的 RecyclerView 无法向上滚动以显示其底部项目。

SO 上有一些类似的问题(例如thisthisthis),但它们没有提供对我有用的解决方案,而且,它们没有对可能导致问题的原因做出任何解释。

一个有趣的注意事项是,如果我旋转或关闭和打开屏幕,它将重建布局和后记,它将正确显示。另外,如果我点击一个项目,它会触发一些东西,这样我就可以滚动那些隐藏的项目。作为一种解决方法,最好调用一个可以手动正确重建布局的函数,但我无法弄清楚它是什么(请参阅下面我尝试做的事情)

我试图做的事情:

  • 将等于工具栏高度的底部边距添加到 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"/> …
Run Code Online (Sandbox Code Playgroud)

android

4
推荐指数
1
解决办法
1365
查看次数

标签 统计

android ×1