0

I'm having a UI problem I've been trying to fix for the past day. To make my TabLayout transparent I need to move it outside the AppBar Layout and when I do so, it becomes transparent all right, but it overlaps the toolbar in the process. like so (please refer to the image):

enter image description here

Here's my layout:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:pp="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<!-- app_bar height @dimen/detail_backdrop_height -->
<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapse_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:contentScrim="@color/colorPrimary"
        app:expandedTitleMarginTop="120dp"
        app:expandedTitleGravity="center|bottom"
        app:expandedTitleTextAppearance="@style/TransparentText">

        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:alpha="0.4"
            app:layout_collapseMode="parallax" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_collapseMode="parallax"
            app:layout_anchor="@+id/app_bar">

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/cover_image"
                android:layout_width="90dp"
                android:layout_height="90dp"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="50dp"
                app:civ_border_color="@android:color/black"
                app:civ_border_width="1dp" />

            <LinearLayout
                android:id="@+id/header_text_layout"
                android:layout_below="@id/cover_image"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/game_title"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="Game title"
                    android:gravity="center"
                    android:textColor="@android:color/white"
                    android:textSize="24sp"/>

                <TextView
                    android:id="@+id/developer_txt"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="Developer"
                    android:gravity="center"
                    android:textColor="@android:color/white"
                    android:textSize="14sp"/>

                <TextView
                    android:id="@+id/publisher_txt"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="Publisher"
                    android:gravity="center"
                    android:textColor="@android:color/white"
                    android:textSize="14sp"/>
            </LinearLayout>

        </RelativeLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?android:attr/actionBarSize"
            app:layout_collapseMode="pin" />

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

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

<android.support.design.widget.TabLayout
    android:id="@+id/tab_layout"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/actionBarSize"
    android:background="@android:color/transparent"
    app:layout_scrollFlags="scroll|enterAlways"
    app:tabGravity="fill"
    app:tabMode="fixed"/>

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</FrameLayout>

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

What I want is a transparent tablayout below my app bar. thank you!

  • You need to put the transparency `android:background="@android:color/transparent"` at the `root` of your `TabLayout` (`AppBarLayout`) and if they have `root` you need repeat again you need to put the transparency on all to have the background. – Crammeur Jul 23 '18 at 22:53

1 Answers1

0

To show the background you need to put the transparency on all root of your TabLayout.

Example :

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme"
    android:background="@android:color/transparent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent">

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

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

<android.support.v4.view.ViewPager
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/appBarLayout">

</android.support.v4.view.ViewPager>

Otherwise is your TabLayout as transparency but not your AppBarLayout so they display is background (AppBarLayout).

Crammeur
  • 678
  • 7
  • 17
  • Excellent it works, but I forgot to put the imageview with the id backdrop also behind the tab layout, is thus possible? –  Jul 24 '18 at 00:53
  • I try and my app bug so I think we can't do that but you can put your `src image` to background of your TabLayout instead of `transparent`. – Crammeur Jul 24 '18 at 01:09
  • I find one thing I think this can do what you want https://stackoverflow.com/questions/4756447/can-we-set-a-background-image-to-tabs – Crammeur Jul 24 '18 at 01:27