ThimoKl
ThimoKl

Reputation: 329

Android Custom TabLayout: Icon overlays content

I'm looking for a custom TabLayout. The icon of the Tab in the middle needs a margin to overlay the content. Please check out the image below.

TabLayout with overlaying icon

What I've tried so far

Re-invent the wheel?

Since I don't need any complicated scrolling functionality, I could develop my own TabLayout with a couple ViewGroups,TextView and ImageView. Before I have to do that:

Any help would be greatly appreciated!

Upvotes: 1

Views: 1681

Answers (1)

Tamas Koos
Tamas Koos

Reputation: 1063

I achieved that by the combination of a custom library and the floating action button. The library: MagicIndicator on GitHub

I set the icon of the middle fragment to an empty icon and positioned the floating action button in the middle to overlay the TabLayout. It looks like this: enter image description here My activity layout:

<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<android.support.v4.view.ViewPager
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="top"
    android:layout_marginBottom="50dp"
    app:layout_behavior="@string/appbar_scrolling_behavior" />

<net.lucode.hackware.magicindicator.MagicIndicator
    android:id="@+id/magic_indicator"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="@color/light_gray"
    android:layout_gravity="bottom" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center|bottom"
    android:layout_margin="10dp"
    app:srcCompat="@drawable/add_icon"
    app:backgroundTint="@color/colorPrimary"/>

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

Upvotes: 1

Related Questions