相关疑难解决方法(0)

无法在NestedScrollView内完全滚动

不知怎的,我无法在NestedScrollView中完全滚动.在我的NestedScrollView里面是一个TextView,它有很多文本,下面有一个按钮.当我向下滚动时,我只能看到按钮的顶部(只有几个像素).它滚动得不够远.

这是我的布局:

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:stateListAnimator="@drawable/appbar_always_elevated"
        android:layout_height="128dp">

    <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed"
            app:toolbarId="@+id/toolbar">

        <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:title="@string/app_name"
                app:layout_collapseMode="pin">

        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>


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

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

        <TextView
                android:id="@+id/textView"
                style="@style/Text.Body1.Medium"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/margin"
                android:layout_marginTop="@dimen/margin"
                android:layout_marginEnd="@dimen/margin"
                android:text="@string/large_text"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/appbar"/>

        <Button
                android:id="@+id/continueButton"
                style="@style/Widget.Button.Green"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/margin"
                android:layout_marginStart="@dimen/margin"
                android:layout_marginEnd="@dimen/margin"
                android:layout_marginBottom="@dimen/margin"
                android:text="@string/continue_text"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"/>
    </LinearLayout>
   </android.support.v4.widget.NestedScrollView>

  </android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

layout android android-layout

5
推荐指数
1
解决办法
568
查看次数

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
查看次数

为什么当 CollapsingToolbarLayout 完全折叠时 NestedScrollView 停止滚动?

我正在使用collapsingToolbarlayoutwithnestedscrollview并且它工作正常,直到collapsingToolbarlayout完全崩溃并actionbar显示。这里nestedscrollview停止滚动,一些项目仍然隐藏。

这是我的 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.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        >

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginEnd="64dp"
            >

            <FrameLayout
                android:id="@+id/topLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax"
                >

                <ImageView
                    android:id="@+id/BigThumbnailImage"
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    android:adjustViewBounds="true"
                    android:fitsSystemWindows="true"
                    android:src="@drawable/bg_health_news"
                    android:scaleType="fitXY" />

            </FrameLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin" />

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

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

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

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

            <include
                android:layout_width="match_parent"
                android:layout_height="0dp"
                layout="@layout/place_item_details_views"
                android:layout_weight="1"
                /> …
Run Code Online (Sandbox Code Playgroud)

android android-coordinatorlayout nestedscrollview

3
推荐指数
1
解决办法
3194
查看次数