Android 折叠工具栏布局:在顶部固定自定义布局
我想做的是:我想在一个折叠工具栏布局中显示一个地图,地图下面应该是一个包含两个控件的自定义布局。下面是一个回收视图。我希望能够滚动自定义布局以及RecyclerView,但修复顶部的自定义布局,同时RecyclerView保持滚动。 下面是我想要实现的图像(灰色=地图;红色=自定义布局;绿色=回收视图): 这是我到目前为止所拥有的。它工作得很好,除了自定义布局(红色)在到达屏幕顶部时不会停止滚动Android 折叠工具栏布局:在顶部固定自定义布局,android,android-layout,android-collapsingtoolbarlayout,Android,Android Layout,Android Collapsingtoolbarlayout,我想做的是:我想在一个折叠工具栏布局中显示一个地图,地图下面应该是一个包含两个控件的自定义布局。下面是一个回收视图。我希望能够滚动自定义布局以及RecyclerView,但修复顶部的自定义布局,同时RecyclerView保持滚动。 下面是我想要实现的图像(灰色=地图;红色=自定义布局;绿色=回收视图): 这是我到目前为止所拥有的。它工作得很好,除了自定义布局(红色)在到达屏幕顶部时不会停止滚动 <?xml version="1.0" encoding="utf-8"?> <
<?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"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="400dp"
android:orientation="vertical"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseMode="parallax"
mapbox:zoom="12"
mapbox:style_url="@string/style_light"
mapbox:access_token="@string/access_token">
</com.mapbox.mapboxsdk.maps.MapView>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<include layout="@layout/current_activity"></include>
<android.support.v7.widget.RecyclerView
android:id="@+id/activity_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
实现这种行为最简单的方法是什么?答案其实很简单。我只需要将自定义布局移到AppBarLayout中 布局如下:
<?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"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="400dp"
app:layout_collapseMode="parallax"
mapbox:zoom="12"
mapbox:style_url="@string/style_light"
mapbox:access_token="@string/access_token">
</com.mapbox.mapboxsdk.maps.MapView>
</android.support.design.widget.CollapsingToolbarLayout>
<include layout="@layout/current_activity"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="?attr/colorAccent"/>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/activity_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
答案其实很简单。我只需要将自定义布局移到AppBarLayout中 布局如下:
<?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"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="400dp"
app:layout_collapseMode="parallax"
mapbox:zoom="12"
mapbox:style_url="@string/style_light"
mapbox:access_token="@string/access_token">
</com.mapbox.mapboxsdk.maps.MapView>
</android.support.design.widget.CollapsingToolbarLayout>
<include layout="@layout/current_activity"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="?attr/colorAccent"/>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/activity_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
将app:layout\u collapseMode=“pin”红色视图中的该属性添加到屏幕顶部的pin。
这可能会解决您的问题将app:layout\u collapseMode=“pin”红色视图中的该属性添加到屏幕顶部的pin。 这可能会解决您的问题