У меня есть следующий макет 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% черной непрозрачности.
Я попробовал то, что было предложено здесь: Похожий вопрос
Однако нет никакой разницы.
EDIT: я понял это и ответил на свой вопрос здесь: Ответить
Важно распознать, что CollapsingToolBarLayout
расширяет FrameLayout
, поэтому вы можете поместить более 1 в An AppBarLayout
, который расширяет LinearLayout
. Вы устанавливаете поведение прокрутки, используя флаги прокрутки, доступные для дочерних представлений AppBarLayout
.