Задаването на гравитация на TabLayout вътре в CollapsingToolbarLayout го кара да изчезне

Имам следното XML оформление:

<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 the TabLayout, the gravity assigned to it (bottom) causes it to disappear. If I remove that, it shows but fixed to the top.

Причината, поради която CollapsingToolBarLayout не съответства на AppBarLayout по размер, е, че експериментирах с поставянето на TabLayout в това пространство и задаването на неговите флагове независимо от CollapsingToolbarLayout директно като наследник на AppBarLayout.

Настройването му независимо работи, но след това вече нямам фона на ImageView с маската 60% черна непрозрачност.

Опитах това, което беше предложено тук: Подобен въпрос

Няма разлика обаче.

РЕДАКТИРАНЕ: Разбрах го и отговорих на собствения си въпрос тук: Отговор

Важното е да разпознаете, че CollapsingToolBarLayout разширява FrameLayout, така че можете да поставите повече от 1 в An AppBarLayout, което разширява LinearLayout. Вие задавате поведението на превъртане, като използвате флаговете за превъртане, достъпни за дъщерните изгледи на AppBarLayout.


person Tunji_D    schedule 08.06.2015    source източник