标签: recyclerview-layout

RecyclerView项目在刷新后更改大小

我有RecyclerView如下图所示:

RecyclerView

这是以下设置代码RecyclerView:

RecyclerView.LayoutManager layoutManager = new GridLayoutManager(this, 2);
dataRecyclerView.setLayoutManager(layoutManager);
dataRecyclerView.addItemDecoration(new GridSpacingItemDecoration(...);
dataRecyclerView.setItemAnimator(new DefaultItemAnimator());
Run Code Online (Sandbox Code Playgroud)

在开始我更新RecyclerView的选定项目的新活动后,RecyclerView将重新填充新数据以反映新的更改,但我得到以下结果:

结果1

当我向下滚动时,我得到了这个差距:

结果2

我打过电话RecyclerView#invalidate(),#invalidateItemDecorations(),#requestLayout()刷新后,但无济于事; 而且我也没有打电话setHasFixedSize(true)RecyclerView.

究竟是什么问题?我如何调整子项目的大小,以便在刷新后准确包装其内容?

(PS:我尝试刷新而没有做任何改动而且没有发生任何事情,这证明了我的理论,即只有在儿童用品的高度发生变化时才会出现问题.)

java android android-recyclerview recyclerview-layout

5
推荐指数
1
解决办法
1318
查看次数

Recyclerview集剪辑儿童

如何让自己的孩子RecyclerViewViewGroup平常的孩子那样互相借鉴clipChildren="false"

我用CardViews我的RecyclerView,我想要一个人的影子CardView覆盖CardView下面。

android android-view android-recyclerview recyclerview-layout

5
推荐指数
1
解决办法
1046
查看次数

有人可以解释RecyclerView.LayoutManager中的getItemCount方法返回什么吗?

该文档对getItemCount()进行了以下说明:

返回绑定到父RecyclerView的适配器中的项目数。请注意,此数字不一定等于State#getItemCount()。

那么,它返回适配器中的所有项目还是屏幕上可见的项目?我不明白 有人可以解释这种方法吗?

android android-recyclerview recyclerview-layout

5
推荐指数
1
解决办法
1889
查看次数

RecyclerView ScrollY 始终为 0

我在片段中有一个 RecyclerView 。我需要收到滚动更改的通知,因此我添加了一个ScrollChange事件回调(对应于SetOnScrollChangeListener经典的 Android API):

private void RecyclerViewScrollChange(object sender, View.ScrollChangeEventArgs e)
{
    int deltaY = e.ScrollY - e.OldScrollY;
}
Run Code Online (Sandbox Code Playgroud)

问题在于 deltaY 始终为零,因为 ScrollY 和 OldScrollY 始终为零。我在回收器视图的布局管理器中使用垂直线性布局,因此应该更新垂直尺寸。什么会导致这个问题?

android xamarin.android android-recyclerview recyclerview-layout

5
推荐指数
1
解决办法
4589
查看次数

如何限制RecyclerView中的项目数?

如何限制RecyclerView 显示的项目数?

如果覆盖getChildCount,我可以限制插入的数量,但这会使它仅插入该数字然后停止。我希望它继续插入/滚动,但只显示 X个项目。

(注意:每个项目的高度都可以不同,因此,限制基于数量而不是某些硬编码值非常重要。)

android recycler-adapter android-recyclerview recyclerview-layout

5
推荐指数
2
解决办法
7625
查看次数

RecyclerView适配器getItemViewType方法有时返回2,8等等而不是0或1

以下是我使用的代码:

public class PaymentAndReceiptAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private static final int TYPE_HEADER = 0;
    private static final int TYPE_ITEM = 1;

    public Context context;
    private List<CustomerAndAmount> customerAndAmountList = new ArrayList<>();
    private PaymentAndReceiptItemClickListener paymentAndReceiptItemClickListener;
    private Map<Long, Double> chartMap;

    public PaymentAndReceiptAdapter(final Context context, final List<CustomerAndAmount> customerAndAmountList, final Map<Long, Double> chartMap, final PaymentAndReceiptItemClickListener paymentAndReceiptItemClickListener) {
        this.context = context;
        setResult(customerAndAmountList, chartMap);
        this.paymentAndReceiptItemClickListener = paymentAndReceiptItemClickListener;
    }

    public void setResult(final List<CustomerAndAmount> customerAndAmountList, final Map<Long, Double> chartMap) {
        this.customerAndAmountList.clear();
        if (null != customerAndAmountList) {
            this.customerAndAmountList.addAll(customerAndAmountList);
        }
        this.chartMap …
Run Code Online (Sandbox Code Playgroud)

android recycler-adapter android-recyclerview recyclerview-layout

5
推荐指数
0
解决办法
367
查看次数

2列的Recycler View水平滚动

到目前为止我已经尝试过了

LinearLayoutManager layoutManager =
        new GridLayoutManager(getActivity(), 2, GridLayoutManager.HORIZONTAL, false);
Run Code Online (Sandbox Code Playgroud)

但它显示2行而不是两列。

如何在回收者视图中以水平滚动显示两个项目?

android recycler-adapter android-recyclerview recyclerview-layout

4
推荐指数
3
解决办法
4937
查看次数

最后如何在 Horizo​​ntal RecyclerView 中显示部分项目以指示滚动?

我试图在这个线程中搜索答案:RecyclerView LinearLayoutManager set item count

但这并不能完全解决我的问题,因为它显示了固定项目。

我想做RecyclerView下图

在此处输入图片说明

正如您在图片中看到的,显示了 3 个项目,但右侧也显示了不完整的项目,以表明该滚动视图可以滚动。我想在recyclerView所有屏幕尺寸中都有那个部分(3 + 1/4)项目。

我使用的item布局的xml是这样的:

<?xml version="1.0" encoding="utf-8"?>

<androidx.cardview.widget.CardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="150dp"
        android:layout_height="250dp"
        app:cardCornerRadius="10dp"
        android:layout_marginRight="8dp"
        app:cardElevation="3dp">

    <androidx.constraintlayout.widget.ConstraintLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/background_light">

        <ImageView
                android:layout_width="0dp"
                android:layout_height="100dp"
                app:srcCompat="@drawable/logo_apps"
                android:id="@+id/productImageView_Item"
                android:layout_marginTop="8dp"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                android:layout_marginStart="8dp"
                app:layout_constraintEnd_toEndOf="parent"
                android:layout_marginEnd="8dp"
                app:layout_constraintDimensionRatio="w,1:1"/>

        <TextView
                android:text="@string/product_name"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:id="@+id/productName_textView_item"
                android:layout_marginTop="8dp"
                app:layout_constraintTop_toBottomOf="@+id/productImageView_Item"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                android:layout_marginStart="4dp"
                app:layout_constraintEnd_toEndOf="parent"
                android:layout_marginEnd="4dp"
                android:textAlignment="center"
                android:minLines="1"
                android:maxLines="2"
                app:autoSizeMinTextSize="8sp"
                app:autoSizeMaxTextSize="14sp"
                android:layout_marginBottom="8dp"/>


    </androidx.constraintlayout.widget.ConstraintLayout>


</androidx.cardview.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

而activity中的recycler view xml是这样的:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".Fragment.HomeFragment" android:background="@color/colorLightGrayBackground"> …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-recyclerview recyclerview-layout

4
推荐指数
1
解决办法
4241
查看次数

获取视图在 GridLayoutManager 上的列号

RecyclerView使用GridLayoutManager具有动态列号的a呈现不同类型的项目。问题是,我有一个RecyclerView.ItemDecoration只适用于让我们说Type A项目。这RecyclerView.ItemDecoration会在左侧列中的那些项目的左侧/开始处添加边距,并在右侧列中的那些项目的右侧/结尾处添加边距。它基本上是为了使项目看起来更居中并因此拉伸(这用于平板电脑/横向模式)。该RecyclerView网格看起来是这样的:

| A | | A |
| A | | A |
   | B |
| A | | A |
| A | | A |
   | B |
| A | | A |
Run Code Online (Sandbox Code Playgroud)

ItemDecoration如下所示:

class TabletGridSpaceItemDecoration(private val space: Int) : RecyclerView.ItemDecoration() {

    override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) = with(outRect) {
        val isTypeAItemLayout = view.findViewById<ConstraintLayout>(R.id.type_a_item_container) != null …
Run Code Online (Sandbox Code Playgroud)

android gridlayoutmanager android-recyclerview recyclerview-layout item-decoration

4
推荐指数
1
解决办法
1018
查看次数

根据项目位置动态更改 StaggeredGridLayout 的列跨度计数

我想为 (n) 项列表实现此布局: 这个布局

到目前为止,我可以在两列中显示项目,但是如何将特定位置的两列合并为一列(即第 7 项)?

我已经尝试过 SO 提供的许多解决方案以及其他解决方案,但没有一个对我有用。那里提供的解决方案要么使用 LinearLayout 膨胀静态布局,要么提供列中分区的解决方案。

我也尝试过使用setSpanLookup方法但没有运气..

java android recyclerview-layout staggeredgridlayoutmanager

4
推荐指数
1
解决办法
2481
查看次数