【问题标题】:NestedScrollView wont't scroll to the end when used with CollapsingToolbarLayout与 CollapsingToolbarLayout 一起使用时,NestedScrollView 不会滚动到最后
【发布时间】:2016-03-22 06:24:19
【问题描述】:

我想将 NestedScrollView 与 CollapsingToolbarLayout 一起使用。在 NestedScrollView 中有很长的内容。不幸的是,我无法滚动到最后。其中一些长内容被剪掉了。当我转动屏幕时奇怪的是,滚动工作正常并且所有内容都可见。

<android.support.design.widget.CoordinatorLayout
    android:fitsSystemWindows="true"
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <android.support.design.widget.AppBarLayout
        android:fitsSystemWindows="true"
        android:layout_height="wrap_content"
        android:layout_width="match_parent">

        <android.support.design.widget.CollapsingToolbarLayout
            android:fitsSystemWindows="true"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:fitsSystemWindows="true"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:scaleType="centerCrop"
                android:src="@drawable/u8"
                app:layout_collapseMode="parallax"/>

            <android.support.v7.widget.Toolbar
                android:layout_height="?attr/actionBarSize"
                android:layout_width="match_parent"
                app:layout_collapseMode="pin"/>

        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:clipToPadding="false"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

            <!-- lots of widgets-->

        </LinearLayout>

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

</android.support.design.widget.CoordinatorLayout>

编辑:我注意到剪切内容的高度与工具栏高度相同。

【问题讨论】:

  • 如果将 LinearLayout 的高度设置为wrap_content 会发生什么?通常,滚动小部件内的任何布局都会在滚动方向上获得wrap_content
  • 什么都没有。仍然无法滚动到最后。
  • 这里有同样的问题。我尝试在某些地方添加 android:fitsSystemWindows="true" 以及 android:windowSoftInputMode="adjustResize" 到清单。到目前为止,所有想法都失败了。
  • 你找到解决办法了吗?
  • 嘿伙计!你找到解决办法了吗?

标签: android layout android-collapsingtoolbarlayout android-appbarlayout nestedscrollview


【解决方案1】:

答案来自here。将 paddingBottom 添加到 NestedScrollView 为我解决了这个问题:

android:paddingBottom="<toolbar height in collapsed state>"

【讨论】:

  • 如果使用工具栏的默认高度可以使用?attr/actionBarSize
【解决方案2】:

我也遇到了类似的问题,即当键盘打开时 NestedScrollView 不会滚动到最后。

在 NestedScrollView 之后放置 AppBarLayout 对我有用。请让我知道它是否适合您。

【讨论】:

    【解决方案3】:

    我遇到了同样的问题。此错误的原因之一是未设置 SupportActionBar

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    

    (我没有这样做,因为我只需要工具栏以使折叠工具栏按预期工作,并且我认为 setSupportActionBar 并不重要)

    另一个是:它在活动内部工作,但在片段中无法正常工作(可能是我使用的支持库的特定版本的问题)

    【讨论】:

      【解决方案4】:

      对我来说这是什么原因是我的 CollapsingToolbarLayout 中的“exitUntilCollapsed”行: app:layout_scrollFlags="scroll|exitUntilCollapsed"&gt;

      与“滚动”一起使用时会导致问题。 我也不能使用marginBottom,因为我有一个即时翻译选项,它用新内容刷新TextViews,当这种情况发生时,它神秘地决定滚动得更远,最终在底部出现一个看起来非常糟糕的空白空间。

      我使用“enterAlwaysCollapsed”解决了这个问题,并将我的工具栏移到了最顶部,在折叠之外。这不是我想要的,但到目前为止我找不到解决方案。

      【讨论】:

      • 真的谢谢,我花了我一周的时间。它对我有用
      【解决方案5】:

      问这个问题已经有一段时间了。但也许像在this answer 中那样在 CollapsingToolbarLayout 中设置minHeight 属性也可能对某人有所帮助。

      【讨论】:

      • 这个答案是正确的,我可以想出一些“类似开发者的解释”来支持这个解决方案,但不能 200% 确定这一点。
      【解决方案6】:

      由于工具栏被固定(使用 CollapsingToolbar)。 Nestedscrollview 无法随屏幕调整底部视图。

      如果您在 setSupportActionBar 上设置了工具栏。 NestedScrollView 将适合屏幕。

      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar); 
      

      【讨论】:

        【解决方案7】:

        使用 app:layout_behavior="@string/appbar_scrolling_view_behavior" 属性和嵌套滚动视图就可以了

        <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.support.design.widget.AppBarLayout
                        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="wrap_content"
                        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
        
                    <android.support.v7.widget.Toolbar
                            android:id="@+id/toolbar"
                            android:layout_width="match_parent"
                            android:layout_height="?attr/actionBarSize"
                            android:background="?attr/colorPrimary"
                            app:layout_scrollFlags="scroll|enterAlways"
                            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
        
                </android.support.design.widget.AppBarLayout>
                <android.support.v4.widget.NestedScrollView
                        android:id="@+id/task_recycler_view"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:fillViewport="true"
                        app:layout_behavior="@string/appbar_scrolling_view_behavior">
                </android.support.v4.widget.NestedScrollView>
            </android.support.design.widget.CoordinatorLayout>
        

        【讨论】:

          猜你喜欢
          • 2020-06-04
          • 1970-01-01
          • 1970-01-01
          • 2017-03-11
          • 2015-09-22
          • 1970-01-01
          • 2015-11-11
          • 1970-01-01
          • 2018-06-01
          相关资源
          最近更新 更多