Reputation: 4329
I'm trying to make collapsing title to center by app:collapsedTitleGravity="center"
in CollapsingToolbarLayout
but actually title
not center. I saw suspicious unnamed-view between title
and up button
I saw a person who occured like me in here.
Here is screen shot
This is suspicious unnamed-view
Here is activity_main
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.profile.detail.ProfileDetailActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/abl_profile"
android:layout_width="match_parent"
android:layout_height="200dp"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/ctl_profile"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
android:layout_marginTop="52dp"
app:expandedTitleMarginStart="16dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:collapsedTitleGravity="center_horizontal">
<android.support.v7.widget.AppCompatImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:src="@mipmap/ic_launcher"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_profile" />
</android.support.design.widget.CoordinatorLayout>
In MainActivity.java
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
style.xml
is
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"/>
Upvotes: 0
Views: 939
Reputation: 76
This will resolve the issue.
android:contentInsetStart="0dp"
android:contentInsetLeft="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
There is padding reserved so that your title is not next to toolbar icon.
Upvotes: 2
Reputation: 23
There is an attribute expandedTitleGravity
that you can use with the CollapsingToolbarLayout
to center the expanded title text. Add this to your CollapsingToolbarLayout
app:expandedTitleGravity="bottom|center_horizontal"
Upvotes: 0