【问题标题】:Extra space between Collapsing Toolbar Title and Home/Up button折叠工具栏标题和主页/向上按钮之间的额外空间
【发布时间】:2016-07-05 17:43:33
【问题描述】:

我正在尝试使用带有主页/向上按钮的折叠工具栏。工具栏折叠后,箭头和标题文本之间有一个额外的空间,我想去掉它。我附上了两张图片,带和不带布局边界,以说明我的观点。

我到处搜索 StackOverflow 并尝试过 安卓:contentInsetStart="0dp" 徒劳的。

这是我的布局 XML 文件。

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:background="?colorPrimary"
        app:elevation="4dp">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="?attr/colorPrimary"
            app:collapsedTitleTextAppearance=
                "@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleTextAppearance=
                "@style/TextAppearance.ExpandedTitle"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:title="Toolbar Title">


            <ImageView
                android:id="@+id/collapsing_toolbar_background"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="88dp"
                android:contentDescription="@string/app_name"
                android:scaleType="centerCrop"
                android:src="@drawable/glider"
                app:layout_collapseMode="parallax"
                />

            <View
                android:id="@+id/toolbar_title_scrim"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:layout_alignBottom="@+id/collapsing_toolbar_background"
                android:layout_gravity="bottom"
                android:background="@android:color/holo_green_light"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:text="test text"
                android:textColor="@android:color/white"/>

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

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

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipToPadding="false"
            android:paddingBottom="16dp"
            android:paddingLeft="16dp"
            android:paddingRight="16dp"
            android:scrollbarStyle="outsideOverlay"/>
    </android.support.v4.widget.SwipeRefreshLayout>

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

【问题讨论】:

    标签: android android-collapsingtoolbarlayout


    【解决方案1】:

    事实证明,这是设计库第 24 版中引入的新材料设计规范的一部分。

    https://material.google.com/patterns/navigation.html

    但是,可以通过将以下属性添加到工具栏小部件来删除多余的空间。

    app:contentInsetStartWithNavigation="0dp"
    

    【讨论】:

    • 这应该是正确的答案,对我也有用! :)
    • 像魅力一样工作。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-08
    • 2018-09-24
    相关资源
    最近更新 更多