【问题标题】:Appbarlayout overlaps with NestedScrollViewAppbarlayout 与 NestedScrollView 重叠
【发布时间】:2016-02-20 18:52:11
【问题描述】:

我有一个协调器布局,它由 appbarlayout 和 nestedscrollview 组成。问题是当我打开活动时,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"
xmlns:card_view="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/my_appbar_container"
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">


    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:contentScrim="@color/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/ivToolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:adjustViewBounds="true"
            android:scaleType="fitXY"
            android:alpha="0.6"
            app:layout_collapseParallaxMultiplier="0.7" />

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

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

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

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

我无法弄清楚这里的问题是什么,也无法在网上找到任何地方。也许这是一个错误。请检查。

【问题讨论】:

  • 为什么要在 NestedScrollView 中设置 app_behavior_overlapTop="-100dp"
  • 啊!我实际上只是想看看会发生什么。在没有它的情况下也面临着这个问题。立即删除。
  • 似乎无法使用该布局文件重现此内容。
  • @AndrewSeymour :我收到此错误。也许是设备特定的错误?你用的是什么设备?
  • 我不知道发生了什么。看起来,如果我向滚动视图添加一些额外的高度,它会正确显示。现在,在这里添加高度意味着我已经尝试过 - 添加一个随机卡片视图或增加任何一个卡片视图的高度。不知道是什么原因。

标签: android android-layout


【解决方案1】:

我遇到了同样的问题,将 NestedScrollView 的布局高度设置为 android:layout_height="wrap_content" 为我解决了这个问题。

希望对你有帮助

【讨论】:

    【解决方案2】:

    我通过在这样的 FrameLayout 中使用 NestedScrollView 解决了这个问题

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

    或者您可以尝试像这样向 NestedScrollView 添加填充

    <android.support.v4.widget.NestedScrollView
            android:background="@color/main_color_white"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="?attr/actionBarSize">
            ................
            ................
    </android.support.v4.widget.NestedScrollView>
    

    【讨论】:

      【解决方案3】:

      不知道为什么,但 this answer 解决了我的问题。 顺便说一句,只有当我更改nestedScrollView 中任何视图的可见性时,我才会遇到这个问题

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-11
        • 2016-03-30
        • 2016-04-04
        • 1970-01-01
        • 2015-12-22
        相关资源
        最近更新 更多