gpt4 book ai didi

android - Recycler view Inside NestedScrollView with CoordinatorLayout

转载 作者:搜寻专家 更新时间:2023-11-01 07:49:13 24 4
gpt4 key购买 nike

下面是代码 fragment ,有人可以帮我吗?我的折叠工具栏根本没有折叠。预期行为是:当我向上滚动时,工具栏应该从 168dp 折叠到 56dp。但它根本没有崩溃。提前致谢。

<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.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/one_primaryColor"
android:fitsSystemWindows="true">

<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="168dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="56dp"
app:layout_collapseMode="pin">

<ImageView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:contentDescription="@string/app_name"

app:layout_collapseMode="parallax"
android:src="@drawable/logo" />

</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<android.support.v7.widget.RecyclerView...

最佳答案

编辑:

我玩过你的布局。您必须使用 NestedScrollView 以使您的布局遵循 CollapsingToolbarLayout 的滚动行为。以下是工作的 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.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/one_primaryColor">


<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="168dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="parallax">


<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/app_name"
android:src="@drawable/logo" />

</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

</RelativeLayout>

</android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>

但是这种方法有一个问题。如果当 root parentCoordinatorLayout 时,将 RecyclerView 放在 NestedScrollView 中。 Recycler 的内容不会显示,尽管调用了所有的适配器方法。背后的原因是滚动布局在滚动内部的嵌套。由于这个原因,很可能没有呈现 Recycler 的布局。为此,已遵循 this 的解决方法。邮政。

在您的代码中,使用 WrappingLinearLayoutManager 类作为回收 View 的布局管理器。

    //Your custom adapter
Adapter adapter = new Adapter(cursor);
adapter.setHasStableIds(true);
mRecyclerView.setAdapter(adapter);
mRecyclerView.setNestedScrollingEnabled(false);

int columnCount = getResources().getInteger(R.integer.list_column_count);
WrappingLinearLayoutManager wrappingLinearLayoutManager =
new WrappingLinearLayoutManager(columnCount, LinearLayout.VERTICAL);
mRecyclerView.setLayoutManager(wrappingLinearLayoutManager);

这应该可以解决您的问题。如果还是不行,我可以帮你上传到某个地方。

关于android - Recycler view Inside NestedScrollView with CoordinatorLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37782032/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com