【问题标题】:RecyclerView scrolling very slow and laggyRecyclerView 滚动非常缓慢和滞后
【发布时间】:2016-11-23 20:17:32
【问题描述】:

嘿,我正在使用带有列表卡片设计的 recyclerview,在每张卡片上我都有一张图片,不是很大,它重 1.5 mb 我正在加载 12 张卡片,但滚动太慢了我尝试使用 PICASSO,但它没有有帮助,问题是当我用更小的图像(300 字节)替换图像时,它可以很好地滚动,但不能解决我的问题..

卡片 xml 的相关部分是:

 <android.support.v7.widget.CardView

        android:id="@+id/card_item"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_gravity="center"

        android:clickable="true"
        card_view:cardCornerRadius="4dp">



        <RelativeLayout

            android:id="@+id/cont_card_content"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:clickable="true"
            android:background="#FFFFFF">



            <ImageView

                android:id="@+id/im_item_icon"

                android:layout_width="wrap_content"

                android:layout_height="170dp"

                android:scaleType="fitXY"

                android:layout_alignParentTop="true"
                android:layout_alignParentStart="true" />

正如我所说,我尝试使用 PICASSO,但没有帮助

Picasso.with(context).load(R.drawable.bg_partyt).into(holder.imageView);

有什么想法吗?

【问题讨论】:

  • 1.5mb 很大,因此请尝试使用 Picasso 的 .fit() 方法。 fit() 将测量目标 ImageView (@+id/im_item_icon) 的尺寸,然后使用 Picasso 自己的 resize() 方法将图像尺寸缩小到目标 ImageView 的尺寸。更多信息在这里:futurestud.io/tutorials/picasso-image-resizing-scaling-and-fit
  • 能贴出包含recyclerView的布局代码吗?
  • 我正在尝试使用 .fit() 但它根本不显示图像。

标签: android performance scroll android-recyclerview


【解决方案1】:

你的图片太大了。

您可以尝试使用 Glide 代替毕加索。它可以更好地处理大图像https://github.com/bumptech/glide

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-23
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 2018-01-30
    • 1970-01-01
    相关资源
    最近更新 更多