如何在android中设置collapsingToolbar的最小高度?

时间:2019-02-13 13:53:25

标签: android android-collapsingtoolbarlayout android-appbarlayout

我有一个collapsingToolbarLayout,如何更改其最小高度?我曾在xml minHeight =“ 100dp”中尝试过,但确实有用。它通常会折叠到顶部。谁能告诉我如何将其最小高度设置为150dp?

 <android.support.design.widget.CoordinatorLayout
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:fitsSystemWindows="true"
            app:layout_constraintBottom_toTopOf="@+id/bottom_nav_master_home"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <android.support.design.widget.AppBarLayout
                android:id="@+id/app_bar_master_home_activity"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="?attr/colorPrimary"
                android:fitsSystemWindows="true"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

                <android.support.design.widget.CollapsingToolbarLayout
                    android:id="@+id/toolbar_collapse"
                    android:layout_width="match_parent"
                    android:layout_height="256dp"
                    android:layout_marginBottom="100dp"
                    android:fitsSystemWindows="true"
                    app:contentScrim="?attr/colorPrimary"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
                    app:titleEnabled="false">

                    <android.support.constraint.ConstraintLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="@color/color_master_background_dark"
                        app:layout_collapseMode="parallax
                        android:background="@color/color_master_background_dark"
                        android:fitsSystemWindows="true"
                        android:scaleType="centerCrop"
                        app:layout_collapseMode="parallax" />
                    <android.support.v7.widget.Toolbar
                        android:id="@+id/toolbar_master_home_activity"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
                        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                        app:title=" "
                        app:titleTextColor="@color/color_text_dark" />

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

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

            <fragment
                android:id="@+id/fragment_nav_host_main_master"
                android:name="androidx.navigation.fragment.NavHostFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:defaultNavHost="true"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                app:navGraph="@navigation/nav_graph_master_main" />

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

我确实添加了marginBottom但仍然没有结果吗?我在这里做错什么了吗?我编辑了上面的代码..

1 个答案:

答案 0 :(得分:1)

将工具栏的底部边距设置为要在折叠版本中保留的任何空间。
来源-setting minHeight in CollapsingToolbarLayout not having any effect