我在AppBarLayout中使用RelativeLayout
进行了CollapsingToolbarLayout<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="360dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content">
<include android:id="@+id/post_meta"
layout="@layout/item_post_meta_layout"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
app:layout_collapseMode="none"
app:layout_scrollFlags="scroll|snap"
/>
<ImageView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/post_meta"
android:fitsSystemWindows="true"
android:minHeight="292dp"
android:scaleType="centerCrop"
app:layout_collapseMode="pin"
app:layout_collapseParallaxMultiplier="0.7"
/>
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
正如你所看到的,在RelativeLayout 2中,我想在滚动时做出不同的行为: 向上滚动时,我的布局(id = post_meta)在图像下滚动,图像固定到工具栏。可能吗?如果是这样,我该怎么做呢?
答案 0 :(得分:2)
所以,我找到了解决办法并以这种方式做到了:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="460dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="460dp"
android:fitsSystemWindows="false"
android:minHeight="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|snap|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
/>
<include android:id="@+id/post_meta"
layout="@layout/item_post_meta_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="340dp"
app:layout_collapseMode="parallax"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed">
<android.support.v4.view.ViewPager
android:id="@+id/post_pager"
layout_collapseParallaxMultiplier="0.7"
android:layout_width="match_parent"
android:layout_height="340dp"/>
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/circlePageInd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="4dp"
app:fillColor="#E0E0E0"
app:pageColor="#FFF"
app:radius="2dp"/>
</RelativeLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:orientation="vertical"
android:paddingBottom="50dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways">
<android.support.v7.widget.RecyclerView
android:id="@+id/chat_rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:clipToPadding="false"
android:fillViewport="true"
android:minHeight="100dp"/>
</RelativeLayout>
<include layout="@layout/send_container"/>
</android.support.design.widget.CoordinatorLayout>
所以,这里post_meta布局在RelativeLayout下使用ViewPager滚动时向上滚动,并在RelativeLayout向下滚动后用ViewPager滚出RelativeLayout。