I used Android support design library to build a profile view for an app I'm working on.
The profile is composed of a header with a header picture as the background and a rounded profile picture on the center. Besides, there ir a small view on the bottom corner of the header.
Below the header is a viewpager with a tablayout.
The problem I'm facing is that there are inconsistencies between Android 5.1.1 and 5.0.2 and below.
Here's how the profile is shown on a Nexus 5 with 5.1.1 Android:
And here's how the profile is shown on a Xperia Z2 with 5.0.2 Android:
Here's the code:
<FrameLayout
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:fitsSystemWindows="true"
android:background="@color/white">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_height="250dp"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/profile_collapsingtoolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/profile_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
app:layout_scrollFlags="scroll|enterAlways"/>
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/profile_image"
android:layout_width="90dp"
android:layout_height="90dp"
app:riv_corner_radius="45dp"
app:riv_border_color="@color/red"
app:riv_border_width="1dp"
android:layout_gravity="center"
app:layout_collapseMode="none"
app:layout_scrollFlags="scroll|enterAlways" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_margin="5dp"
android:layout_gravity="bottom|right"
android:background="@drawable/shape_usertype_background">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="@color/white"
android:text="Professional"/>
</FrameLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/profile_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/profile_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:paddingTop="45dp"/>
<android.support.design.widget.TabLayout
android:id="@+id/profile_tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:tabGravity="center"
app:tabMode="scrollable"
app:tabIndicatorColor="@color/red"
app:tabTextColor="@color/main_dark"
app:tabSelectedTextColor="@color/red"
android:fitsSystemWindows="true"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom"
android:background="@color/white"
/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/profile_floatingbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="@android:drawable/ic_menu_share"
app:backgroundTint="@color/red"
app:layout_anchor="@id/profile_pager"
app:layout_anchorGravity="bottom|right|end"
app:rippleColor="@android:color/darker_gray"
app:borderWidth="0dp"/>
</android.support.design.widget.CoordinatorLayout>
</FrameLayout>
So, anyone has an idea on how to fix this?
Thanks!
Design Library is unfortunately quite buggy and it should be considered "beta" rather than production ready. It looks and behaves differently depending on Android version your app is running on and problems I spotted are not only related to CoordinatorLayout
, but even relatively simple widget like TextInputLayout
is not working the same way everywhere. Knowing design library is quite fresh product, I am not sure it is worth spending your own time working around (not fixing) Google bugs. I'd just wait for next iteration of the library, expecting improvements and bug fixes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With