NestedScrollView wont't scroll to the end when used with CollapsingToolbarLayout

旧街凉风 提交于 2019-12-18 15:06:03

问题


I want to use NestedScrollView with CollapsingToolbarLayout. In NestedScrollView there is really long content. Unfortunately I can't scroll to the end. Some of this long content is cut. What is strange when I turn screen, scrolling works fine and all content is visible.

<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>

EDIT: I noticed that height of cut content is the same as Toolbar height.


回答1:


I was also facing the similar issue where the NestedScrollView wouldn't scroll to the end when the keyboard is open.

Placing the AppBarLayout after the NestedScrollView did the trick for me. Do let me know if it works for you.




回答2:


Answer taken from here. Adding paddingBottom to NestedScrollView resolved this issue for me:

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



回答3:


I had the same issue. One of the reasons for this bug was not setting the SupportActionBar

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

(I didn't to do it because I needed toolbar only for the collapsing toolbar to work as expected and I thought it wasn't important to setSupportActionBar)

And the other one was: it was working inside the activity, but in a fragment wasn't working correctly (maybe it was an issue of that specific version of support library that I used)




回答4:


What causes this for me is "exitUntilCollapsed" line in my CollapsingToolbarLayout: app:layout_scrollFlags="scroll|exitUntilCollapsed">

It causes problem when used with "scroll". I couldn't also use marginBottom because I have an instant translate option which refreshes the TextViews with new content, and when that happens it mysteriously decides to scroll even further more, which ends up in a really bad looking empty space at the bottom.

I solved it using "enterAlwaysCollapsed" instead and moved my toolbar to the very top, outside the collapse. It's not exactly what I want but so far I couldn't find a solution.




回答5:


It's been a while since asking the question. But maybe setting minHeight attribute in CollapsingToolbarLayout like in this answer might help somebody as well.




回答6:


Due to Toolbar pinned(with CollapsingToolbar). Nestedscrollview failed to adjust the bottom view with the screen.

If you set toolbar on the setSupportActionBar. NestedScrollView will fit with the screen.

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



回答7:


Use app:layout_behavior="@string/appbar_scrolling_view_behavior" property and nested scroll view it will work

<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>


来源:https://stackoverflow.com/questions/34306559/nestedscrollview-wontt-scroll-to-the-end-when-used-with-collapsingtoolbarlayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!