【问题标题】:NestedScrollView + AppBarLayout content goes behindNestedScrollView + AppBarLayout 内容落后
【发布时间】:2016-03-30 00:34:35
【问题描述】:

我已经实现了类似的设计 https://github.com/chrisbanes/cheesesquare

一个可折叠的工具栏,里面有一个图像,向下滚动时会折叠

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

        <android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            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"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginEnd="64dp"
                app:expandedTitleMarginStart="48dp"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
                    android:id="@+id/pager"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/picture_heigth"
                    android:fitsSystemWindows="true"
                    app:layout_collapseMode="parallax">

                </android.support.v4.view.ViewPager>


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


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

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/scroll_view"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"         
            android:foreground="?android:windowContentOverlay"

            app:layout_behavior="@string/appbar_scrolling_view_behavior">
            LinearLayout
            android:id="@+id/root"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

效果很好,但并非总是如此......例如,在线性布局中,我有一个视图,在我的休息请求完成后会被填充。这具有将内容推送到 Viewpager 后面的效果,当我再次向下和向上滚动时,所有内容都会再次进入正确的位置。

我在一些 SO 线程上看到,通过在 NestedSCrollVew 上设置“fill_vertical”可以解决一些问题。实际上确实如此,内容不会落后,但滚动视图的底部已被剪切...... 通过放置一些底部边距,它可以解决问题,但它是动态的,我不知道提前放置什么边距......

【问题讨论】:

  • 得到答案了吗?

标签: android dynamic nestedscrollview behind


【解决方案1】:

添加到您的 LinearLayout 焦点属性:

        android:focusable="true"
        android:focusableInTouchMode="true"

【讨论】:

    【解决方案2】:

    一种解决方案是在NestedScrollView 上设置填充并将填充剪切设置为 false,如下所示:

    android:paddingTop="?actionBarSize"
    android:clipToPadding="false"
    

    (Ref1) (Ref2)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多