滑动 RecyclerView
Sliding RecyclerView
我在 LinearLayout
中有一个 RecyclerView
。我怎样才能让 LinearLayout "slide" 向上直到它到达应用程序栏,然后 RecyclerView
应该像往常一样开始滚动项目。同样,当到达列表中的第一项时,向下滚动列表将开始 "slide" 整个容器向下滚动,直到容器 returns 到其起始位置。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/nearby_stops"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="@dimen/half_padding"
android:paddingTop="@dimen/half_padding"
android:scrollbars="none" />
</LinearLayout>
我看了https://github.com/umano/AndroidSlidingUpPanel,但是不支持RecyclerView
和现在
将 RecyclerView
放在 Fragment
中,因此为 Fragment
创建一个 XML:
这是您的 XML RecyclerView
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/nearby_stops"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="@dimen/half_padding"
android:paddingTop="@dimen/half_padding"
android:scrollbars="none" />
</LinearLayout>
然后对于托管 Fragment
的 Activity
只需为 Fragment
添加一个 FrameLayout
:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Put other views here -->
<FrameLayout
android:id="@+id/slidingFragmentContent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
然后在实例化 Fragment
时在 Activity
中执行以下操作:
SampleFragment listFragment = new SampleFragment();
getSupportFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.abc_slide_in_bottom, R.anim.abc_slide_out_bottom,
R.anim.abc_slide_in_bottom, R.anim.abc_slide_out_bottom)
.addToBackStack(null)
.add(R.id.slidingFragmentContent, listFragment)
.commit();
动画 R.anim.abc_slide_in_bottom
和 R.anim.abc_slide_out_bottom
在 Android API 中可用。
我还注意到您没有为 LinearLayout
设置任何方向。像这样设置方向 android:orientation="..."
您可以分配一个 Button
来显示 Fragment
,像这样:
mButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showFragment();
}
});
-------------------------------------------- ----------------------
要让 RecyclerView
在滚动时向上滚动,只需使用以下命令:
为您的 Activity
创建一个 XML 布局:
<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="@dimen/map_view_height"
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">
<YourCustomViewContainingTheMap
app:layout_collapseMode="parallax"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
在 FrameLayout
内给你的 Fragment
充气,然后当你向上滚动时它应该在 Map
上做一个视差动画。如果您不想要 Parallax
效果,只需设置 app:layout_CollapseMode="pin"
这是我创建的一个示例应用程序,当我在 RecyclerView
上向上滚动时,您可以看到它向上滑动:
(请注意 GIF 上的帧动画不是很好)
要在地图上的滑动列表后面获得阴影,只需将 app:layout_collapseMode
设置为 parallax
,然后在 [=41= 内的 MapView
前面添加另一个视图] 可以是你的面具,它可以是一个简单的视图,然后你可以在向上滚动列表时调整它的 alpha 值。
最好使用原生 android 视图,我注意到 AndroidSlidingPanelLayout
有大约 43 个问题。
我在 LinearLayout
中有一个 RecyclerView
。我怎样才能让 LinearLayout "slide" 向上直到它到达应用程序栏,然后 RecyclerView
应该像往常一样开始滚动项目。同样,当到达列表中的第一项时,向下滚动列表将开始 "slide" 整个容器向下滚动,直到容器 returns 到其起始位置。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/nearby_stops"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="@dimen/half_padding"
android:paddingTop="@dimen/half_padding"
android:scrollbars="none" />
</LinearLayout>
我看了https://github.com/umano/AndroidSlidingUpPanel,但是不支持RecyclerView
和现在
将 RecyclerView
放在 Fragment
中,因此为 Fragment
创建一个 XML:
这是您的 XML RecyclerView
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/nearby_stops"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="@dimen/half_padding"
android:paddingTop="@dimen/half_padding"
android:scrollbars="none" />
</LinearLayout>
然后对于托管 Fragment
的 Activity
只需为 Fragment
添加一个 FrameLayout
:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Put other views here -->
<FrameLayout
android:id="@+id/slidingFragmentContent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
然后在实例化 Fragment
时在 Activity
中执行以下操作:
SampleFragment listFragment = new SampleFragment();
getSupportFragmentManager().beginTransaction()
.setCustomAnimations(R.anim.abc_slide_in_bottom, R.anim.abc_slide_out_bottom,
R.anim.abc_slide_in_bottom, R.anim.abc_slide_out_bottom)
.addToBackStack(null)
.add(R.id.slidingFragmentContent, listFragment)
.commit();
动画 R.anim.abc_slide_in_bottom
和 R.anim.abc_slide_out_bottom
在 Android API 中可用。
我还注意到您没有为 LinearLayout
设置任何方向。像这样设置方向 android:orientation="..."
您可以分配一个 Button
来显示 Fragment
,像这样:
mButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showFragment();
}
});
-------------------------------------------- ----------------------
要让 RecyclerView
在滚动时向上滚动,只需使用以下命令:
为您的 Activity
创建一个 XML 布局:
<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="@dimen/map_view_height"
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">
<YourCustomViewContainingTheMap
app:layout_collapseMode="parallax"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
在 FrameLayout
内给你的 Fragment
充气,然后当你向上滚动时它应该在 Map
上做一个视差动画。如果您不想要 Parallax
效果,只需设置 app:layout_CollapseMode="pin"
这是我创建的一个示例应用程序,当我在 RecyclerView
上向上滚动时,您可以看到它向上滑动:
(请注意 GIF 上的帧动画不是很好)
要在地图上的滑动列表后面获得阴影,只需将 app:layout_collapseMode
设置为 parallax
,然后在 [=41= 内的 MapView
前面添加另一个视图] 可以是你的面具,它可以是一个简单的视图,然后你可以在向上滚动列表时调整它的 alpha 值。
最好使用原生 android 视图,我注意到 AndroidSlidingPanelLayout
有大约 43 个问题。