[英]Android Navigation Drawer Animation Lags/Slows down when an Image View is added over Recycler view
I am having a recyclerview inside a relative layout and the app is working fine, the navigation drawer is smooth. 我在相对布局中有一个recyclerview,应用程序运行正常,导航抽屉很流畅。 But I added an Imageview over the recycler view so that I can hide and show based on the availability of the data.
但是我在回收者视图上添加了一个Imageview,以便可以根据数据的可用性进行隐藏和显示。 But soon as I have added the Imageview the navigation drawer becomes very slow.
但是,一旦我添加了Imageview,导航抽屉就会变得非常缓慢。 And when I remove the Imageview it again works smooth.
当我删除Imageview时,它又可以正常工作了。 The image size is just 38kb.
图像大小仅为38kb。 Can someone tell me how to show empty state in an efficient way
有人可以告诉我如何有效显示空状态吗
This is my Layout with the ImageView 这是我与ImageView的布局
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.test.sample.itemHistory"
tools:showIn="@layout/app_bar_item_history"
android:background="#ffffff">
<android.support.v7.widget.RecyclerView
android:id="@+id/materialList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/imageViewNoItems"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@drawable/noItems" />
</RelativeLayout>
Thanks in Advance 提前致谢
used picasso or glide library for image loading.. and also add one line in your manifest and your project become smooth as before. 使用毕加索或glide库进行图像加载..并在清单中添加一行,从而使项目像以前一样平滑。
<application
android:largeHeap="true">
</application>
largeHeap is used to avoid outofmemory exception while loading images. largeHeap用于避免加载图像时出现内存不足异常。
In my case, I try to load Image (PNG File within the Project Drawable Resource Folder) to my RecycleView's ImageView as well using Picasso and I facing the same problem where the Navigation Drawer sliding animation is being slow down. 就我而言,我也尝试使用Picasso将图像(项目Drawable Resource文件夹中的PNG文件)加载到RecycleView的ImageView中,并且遇到导航抽屉滑动动画速度变慢的相同问题。
I found that the main issue is because my Image File is quite Large so the Picasso load the Full Size image into the RecycleView's ImageView which would cause the Lag . 我发现的主要问题是,因为我的图像文件是相当大的 ,因此毕加索加载全尺寸图像到RecycleView的ImageView的,这将导致滞后 。
My Solution are: (I am using KOTLIN Language) 我的解决方案是:(我正在使用KOTLIN语言)
Without Resize (Which Cause Lag):
没有调整大小(导致滞后):
Picasso.get().load(R.drawable.icon).into(holder.view.ImageView)
Resized (Solve Lag Problem):
调整大小(解决滞后问题):
Picasso.get().load(R.drawable.icon).resize(400,400).centerCrop().into(holder.view.ImageView)
This Method does not required to Resize the image:
此方法不需要调整图像大小:
holder.view.ImageView.setImageDrawable(holder.view.ImageView.context.resources.getDrawable(R.drawable.icon))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.