如何在CollapsingToolbarLayout中居中扩展标题

时间:2015-07-08 14:10:05

标签: android android-layout android-collapsingtoolbarlayout

我想在展开布局时将工具栏标题居中,这是我的代码:

NULL

2 个答案:

答案 0 :(得分:1)

您只需更改这两个属性的值

即可
    app:expandedTitleMarginEnd="64dp"
    app:expandedTitleMarginStart="48dp"

in

   <android.support.design.widget.CollapsingToolbarLayout
    android:id="@+id/collapsing_toolbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_scrollFlags="scroll|exitUntilCollapsed"
    android:fitsSystemWindows="true"
    app:contentScrim="?attr/colorPrimary"       
    app:expandedTitleMarginStart="48dp"
    app:expandedTitleMarginEnd="64dp"
    app:expandedTitleMarginBottom="60dp">

答案 1 :(得分:1)

尝试将 expandedTitleGravity 添加到 CollapsingToolbarLayout 作为应用属性:

app:expandedTitleGravity="center_horizontal"

示例:

<android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="@color/colorPrimary"
        app:expandedTitleGravity="center_horizontal"            
        app:layout_scrollFlags="scroll|exitUntilCollapsed">