Android 使用ChildView协调折叠线性布局
嘿,这里我有一个布局,主要有两个Android 使用ChildView协调折叠线性布局,android,android-layout,android-coordinatorlayout,Android,Android Layout,Android Coordinatorlayout,嘿,这里我有一个布局,主要有两个视图,顶部的一个用于选择,底部的一个显示内容(滚动视图,带有列表视图)。 我想要的行为是,当我滚动浏览内容时,上面的视图会折叠或展开(折叠工具栏布局类似) 目前,我使用layout\u权重实现了整个布局,我不知道如何正确实现调整视图大小的CoordinateLayout 布局如下: <LinearLayout android:layout_width="match_parent" android:layout_height="match_pa
视图
,顶部的一个用于选择,底部的一个显示内容(滚动视图
,带有列表视图
)。
我想要的行为是,当我滚动浏览内容时,上面的视图会折叠或展开(折叠工具栏布局
类似)
目前,我使用layout\u权重实现了整个布局,我不知道如何正确实现调整视图大小的CoordinateLayout
布局如下:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/preview_wrapper"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp">
<android.support.v4.view.ViewPager
android:id="@+id/view_pager_preview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.4">
</android.support.v4.view.ViewPager>
<CustomIndicator
android:id="@+id/pager_indicator"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5">
<android.support.v4.view.ViewPager
android:id="@+id/view_pager_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/view_pager_preview">
<ScrollView
android:id="@+id/scroll_view"
android:focusable="false"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ScrollView>
</android.support.v4.view.ViewPager>
</LinearLayout>
</LinearLayout>
如果有人能解释一下在这种情况下如何实现CoordinateLayout
,CollingToolbarLayout
和AppBarLayout
。如果你想让你的顶部ViewPager
折叠,我会把它放在CoordinatorLayout
的顶部。大概是这样的:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/main.appbar"
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:layout_width="match_parent"
android:layout_height="wrap_content"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll"
app:contentScrim="?attr/colorPrimary"
app:layout_collapseMode="pin">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:background="@color/transparent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="parallax">
</android.support.v7.widget.Toolbar>
<android.support.v4.view.ViewPager
android:id="@+id/viewpagerTop"
android:background="@android:color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpagerBottom"
android:background="@android:color/white"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"/>
嘿,谢谢你提供这篇文章,是否需要用AppBarLayout和CollingToolBarLayout包装ViewPager?因为在我的例子中,AppBar和Toolbar的内容就像我在上面发布的布局一样被包括在内。根据我从你的问题中了解到的,如果你想在滚动底部页面时顶部的ViewPager
折叠,使用协调器布局并将顶部布局放在折叠工具栏中似乎是最简单的方法