【问题标题】:CollapsingToolbarLayout doesn't work well with NestedScrollViewCollapsingToolbarLayout 不适用于 NestedScrollView
【发布时间】:2015-09-25 03:11:40
【问题描述】:

我做了一个活动,其中图像应使用工具栏折叠,并且只有下面的文本可见。但是当Toolbar被折叠时,Toolbar和NestedScrollView之间会出现很大的差距

<android.support.design.widget.CoordinatorLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:background="@color/white"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        app:elevation="5dp"
        app:layout_collapseMode="pin"
        android:fitsSystemWindows="true"
        android:layout_height="wrap_content">

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

            <com.noframe.farmisagronom.util.ResizibleImageView
                android:id="@+id/image_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
                android:minHeight="100dp"
                android:maxHeight="400dp"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.5"
                android:scaleType="centerCrop"/>

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

        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.widget.NestedScrollView
        android:id="@+id/nesteview"
        app:layout_anchorGravity="top"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
         .....
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

而且这个活动看起来很不错。

但是当我向上滚动 NestedScrollView 时,这会失控。

工具栏和文本之间的这个小空间让我很紧张。

注意如果NestedScrollView有大文本问题是不会显示出来的,但是如果NestedScrollView+折叠工具栏没有占满手机屏幕,那么它们之间就有空隙了。

【问题讨论】:

    标签: android material-design android-collapsingtoolbarlayout


    【解决方案1】:

    添加:

    android:layout_gravity="fill_vertical"
    

    到为我工作的NestedScrollView

    【讨论】:

    • 这到底是做什么的?
    • 它强制 NestedScrollView 在 CollapsingToolbar 折叠时垂直填充其容器(CoordinatorLayout)。
    • 奇怪的是 NestedScrollView 没有 layout_gravity 属性,但如果你把它放在任何地方,它不会被拒绝并且它可以工作......但是在这个问题之后,如果里面的视图是滚动的,你会遇到滚动问题可点击。对于这个检查问题:stackoverflow.com/questions/31136740/…
    • @Davidea NestedScrollView 扩展 FrameLayout 扩展 ViewGroup 扩展 View。所有这些超类都有它们的属性
    • 无法为我工作。虽然我在另一个里面有一个嵌套的 CoordinatorLayout,但具有 BottomSheet 行为。 BottomSheet 包含应用栏。只有在默认情况下打开 BottomSheet 并且在启动应用程序时屏幕处于打开状态时才会出现此问题。如果屏幕被锁定并启动应用程序,则没有问题。
    猜你喜欢
    • 1970-01-01
    • 2015-09-22
    • 2021-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-25
    • 2015-08-29
    • 2015-10-22
    相关资源
    最近更新 更多