amlwin
amlwin

Reputation: 4329

app:collapsedTitleGravity="center" doesn't work properly

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

  1. Is it issue form design support lib?
  2. Is there any way to overcome this?

I saw a person who occured like me in here.

Here is screen shot

Title is not center suspicious unnamed-view is occured

This is suspicious unnamed-view enter image description here

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

Answers (2)

Poe Poe
Poe Poe

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

Kannan Kumar
Kannan Kumar

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

Related Questions