【问题标题】:How to remove space in Toolbar [duplicate]如何删除工具栏中的空间[重复]
【发布时间】:2017-10-19 14:42:46
【问题描述】:

我想删除 Toolbar 和 TextView 之间的这个空间,如下图所示:

我尝试使用 contentInsetStartcontentInsetEnd 但也无法正常工作。 这是我处理它的完整代码

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="@dimen/app_bar_height"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/ctl_news"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleTextAppearance="@style/CollapsingToolbarLayoutExpandedTextStyle"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/iv_news_mainImage"
            android:layout_width="match_parent"
            android:layout_height="230dp"
            android:scaleType="centerCrop"
            android:src="@drawable/stripes"
            app:layout_collapseMode="parallax"
            app:layout_collapseParallaxMultiplier="0.7" />

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

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/back"
                android:gravity="top|end"
                android:textColor="@color/white"
                android:textSize="@dimen/text_huge_size" />
        </android.support.v7.widget.Toolbar>

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

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

谁能帮我解决一下

【问题讨论】:

  • 使用重力!或对齐父中心为真
  • 在 TextView 中尝试android:gravity="left"

标签: android xml toolbar


【解决方案1】:

使用应用命名空间并这样做:

app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"

另外,您可能需要添加:

app:contentInsetStartWithNavigation="0dp"

移除 contentInsetEnd 属性。我试过了,这行得通

所以它看起来像这样:

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        app:contentInsetLeft="0dp"
        app:contentInsetStart="0dp"
        app:contentInsetStartWithNavigation="0dp"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

【讨论】:

    【解决方案2】:

    你试试app:titleMarginStart="0dp"吗?

    您应该为contentInsetStartcontentInsetEnd 使用app 前缀并删除android 以避免样板代码

    【讨论】:

    • 我也尝试过,但不起作用也删除android前缀和相同的结果
    • 你尝试app:contentInsetStartWithNavigation了吗?
    • app:contentInsetStartWithNavigation 对我有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多