Appbarlayout与NestedScrollView重叠

4
我有一个协调布局,包括appbarlayout和nestedscrollview。问题是当我打开活动时,nestedscrollview的一部分默认隐藏在扩展的操作栏后面(图像中显示的差异)。

This is what I get This is what it should be

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

我无法确定问题所在,并且在网上找不到任何信息。也许这是一个错误。请检查。

1
你为什么在NestedScrollView中设置了_app_behavior_overlapTop="-100dp"? - Rick
您IP地址为143.198.54.68,由于运营成本限制,当前对于免费用户的使用频率限制为每个IP每72小时10次对话,如需解除限制,请点击左下角设置图标按钮(手机用户先点击左上角菜单按钮)。 - Yash
似乎无法使用该布局文件重现此问题。 - Andrew Seymour
@AndrewSeymour:我收到了这个错误。可能是设备特定的错误吗?你使用的是哪个设备? - Yash
我不知道发生了什么。看起来,如果我给滚动视图添加一些额外的高度,它就会正确显示。现在,在这里添加高度意味着我已经尝试过 - 添加一个随机的卡片视图或增加任何一个卡片视图的高度。不知道原因是什么。 - Yash
有人解决了这个问题吗?我遇到了几乎相同布局的同样问题。而且它只出现在Galaxy S6 Edge +上。 - OMArikan
3个回答

0

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

希望能帮到你


0

不知道为什么,但这个答案解决了我的问题。 顺便说一下,我只有在更改nestedScrollView内任何视图的可见性时才遇到了这个问题。


0

我通过将NestedScrollView放在FrameLayout中来解决这个问题,就像这样

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接