相关疑难解决方法(0)

是否有与RecyclerView相同的addHeaderView?

我正在为回收者视图寻找相当于addHeaderView的东西.基本上我想要一个带有2个按钮的图像作为标题添加到列表视图中.是否有不同的方法将标题视图添加到回收站视图?指导的一个例子会很有帮助

编辑2(添加片段布局):

添加日志语句后,似乎getViewType只接收到0的位置.这导致onCreateView只加载一个布局:

10-26 16:32:53.766    5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766    5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766    5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766    5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766    5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766    5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766    5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766    5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766    5449-5449/co.testapp I/logger info? Adapter-> getItemCount: 5
10-26 16:32:53.766    5449-5449/co.testapp I/logger info? …
Run Code Online (Sandbox Code Playgroud)

android android-view android-recyclerview

279
推荐指数
10
解决办法
19万
查看次数

处理RecyclerView,NestedScrollView和CardView

我将在我的应用程序中实现此UI: UI

好吧,我之前尝试过的一些方法:

1.使用CollapsingToolbarLayout 我把我CardView的insid CollapsingToolbarLayout并把他们都在AppBarLAyout.

<android.support.design.widget.CoordinatorLayout
    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:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

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

            <CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                />
                  <!-- My Views Goes there -->
            </CardView

            <android.support.v7.widget.Toolbar
                android:id="@+id/flexible.example.toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@null"
                app:layout_collapseMode="pin"
                style="@style/ToolBarWithNavigationBack"
                />
        </android.support.design.widget.CollapsingToolbarLayout>

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

    <RecyclerView
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
    ></RecyclerView>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

PS:我删除了不相关的代码,不提我

这种方式正常但是!!! 当CardView高度高于屏幕高度时,它的内容由AppBarLayout用户显示并且不向用户显示

2.使用NestedScrollView 我放入CardViewRecyclerView内部NestedScrollView.但问题是当用户到达时回收到RecyclerView,然后滚动回到顶部,fling会变得迟钝和错误并停止一些用户必须滚动越来越多的地方!

<android.support.v4.widget.NestedScrollView
    android:id="@+id/nested_scrollbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="fill_vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:scrollbars="none" >
        <LinearLayout
            android:id="@+id/nested_scrollbar_linear"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

                <android.support.v7.widget.CardView
                    android:id="@+id/flexible.example.cardview"
                    android:layout_width="match_parent" …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview android-collapsingtoolbarlayout android-appbarlayout nestedscrollview

6
推荐指数
1
解决办法
6586
查看次数

嵌套在垂直 RecyclerView 中的垂直 RecyclerView

我花了几个小时/几天来阅读这个主题,但仍然找不到有用的东西。我试图RecyclerView在另一个垂直滚动的行中放置一个固定高度的垂直滚动RecyclerView

大部分建议都是“将垂直滚动RecyclerView放入另一个垂直滚动中是一种犯罪行为RecyclerView”......但我不明白为什么这如此糟糕。

事实上,行为几乎与 StackOverflow 上的许多页面完全相同(例如,这个……实际上这个问题,至少在移动设备上查看时),其中代码部分是固定的(或最大) 高度和垂直滚动,并且包含在本身垂直滚动的页面中。发生的情况是,当焦点在代码部分时,滚动发生在该部分内,当它到达该部分滚动范围的上/下端时,则滚动发生在外页内。这是很自然的,不是邪恶的。

这是我的 recycler_view_row_outer.xml(外层中的一行RecyclerView):

<com.google.android.material.card.MaterialCardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    style="@style/MyCardView"
    app:cardElevation="4dp"
    app:strokeColor="?attr/myCardBorderColor"
    app:strokeWidth="0.7dp"
    card_view:cardCornerRadius="8dp" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            style="@style/MyTextView.Section"
            android:id="@+id/list_title" />

        <LinearLayout
            style="@style/MyLinearLayoutContainer"
            android:id="@+id/list_container"
            android:layout_below="@+id/list_title" >
        </LinearLayout>

    </RelativeLayout>

</com.google.android.material.card.MaterialCardView>
Run Code Online (Sandbox Code Playgroud)

这是我的recycler_view_row_inner.xml(内部的一行RecyclerView):

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/my_constraint_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/list_container" >

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_view_inner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbarStyle="outsideOverlay"
        android:scrollbars="vertical"
        app:layout_constrainedHeight="true"
        app:layout_constraintBottom_toBottomOf="@+id/my_constraint_layout"
        app:layout_constraintEnd_toEndOf="@+id/my_constraint_layout"
        app:layout_constraintHeight_max="750dp"
        app:layout_constraintHeight_min="0dp"
        app:layout_constraintStart_toStartOf="@+id/my_constraint_layout"
        app:layout_constraintTop_toTopOf="@+id/my_constraint_layout" >
    </androidx.recyclerview.widget.RecyclerView> …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview

4
推荐指数
2
解决办法
401
查看次数

回收商视角的标题,2020 年的最佳实践是什么?

我有一个回收者的观点。我想向回收站视图添加一个标题,以便它与回收站视图一起滚动。多年前,选项是:

  1. 将回收器视图和标题布局嵌套在NestedScrollView. 这样做的缺点是这意味着回收者视图不会像它应该的那样运行。
  2. 修改回收器视图,使其处理两种视图类型,一种用于标题,另一种用于常规回收器视图项。

2020年我们在哪里?这仍然是两种选择吗?如果是这样,#2 仍然是推荐的选项吗?

谢谢。

android android-recyclerview

0
推荐指数
1
解决办法
522
查看次数