Setting gravity to TabLayout inside CollapsingToolbarLayout makes it diassapear

I have the following XML layout:

<android.support.design.widget.CoordinatorLayout 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:orientation="vertical">

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="192dp"
    android:background="@drawable/bg_bucket_list">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="144dp"
        app:expandedTitleMarginBottom="@dimen/quadruple_margin"
        app:layout_collapseParallaxMultiplier="0.7"
        app:layout_scrollFlags="scroll|enterAlwaysCollapsed">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="top"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"
            android:src="@drawable/bg_bucket_list" />

        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentTop="true"
            android:layout_gravity="top"
            android:background="@color/black_40" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="top"
            android:animateLayoutChanges="true"
            android:gravity="top">

            <TextView
                android:id="@+id/text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginLeft="@dimen/single_margin"
                android:layout_marginStart="@dimen/single_margin"
                android:layout_marginTop="@dimen/quadruple_margin"
                android:text="@string/my_places_for"
                android:textColor="@color/white"
                android:textSize="24sp"
                android:visibility="gone" />

            <TextView
                android:id="@+id/sub_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/text"
                android:layout_marginLeft="@dimen/single_margin"
                android:layout_marginStart="@dimen/single_margin"
                android:layout_marginTop="@dimen/quarter_margin"
                android:text="@string/pick_category_or_business"
                android:textColor="@color/white"
                android:textSize="16sp"
                android:visibility="gone" />
        </RelativeLayout>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_gravity="bottom"
            app:layout_collapseMode="pin"
            app:layout_scrollFlags="scroll|enterAlways"
            app:tabBackground="@color/transparent"
            app:tabGravity="center"
            app:tabMode="fixed"
            app:tabSelectedTextColor="@color/white"
            app:tabTextColor="@color/grey_400" />

        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="@dimen/abc_action_bar_default_height_material"
            app:contentInsetLeft="@dimen/triple_margin"
            app:contentInsetStart="@dimen/triple_margin"
            app:popupTheme="@style/Theme.AppCompat.NoActionBar"
            app:theme="@style/Theme.AppCompat.NoActionBar" />
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

      

If you look at TabLayout

, the gravity assigned to it (at the bottom) will make it disappear. If I remove this, it shows up but is fixed at the top.

The reason I don't have one CollapsingToolBarLayout

that matches the size AppBarLayout

is because I experimented with placing TabLayout

in that space and setting flags independently of being CollapsingToolBarLayout

directly as a descendant AppBarLayout

.

Setting it up independent works, but then I have no background ImageView with mask mask mask 60%.

I tried what was suggested here: Similar question

There is no difference.

EDIT: I figured it out and answered my own question: Answer

It's important to know CollapsingToolBarLayout

extends FrameLayout

, so you can add more than 1 to An AppBarLayout

, which extends LinearLayout

. You set the scrolling behavior with the scroll flags available for the child views AppBarLayout

.

+3


source to share





All Articles