我有一个自定义 ListView ,显示用户,还有照片 我从 API 检索数据,它给出 JSON 输出,
我的问题是 ListView 滚动不流畅,它挂起一秒钟然后滚动,重复同样的操作直到我们到达终点。
我认为这可能是我在 UI 线程上运行与网络相关的操作,但它甚至在完成加载后仍继续这样做?
我的自定义Listview的结构是
<TextView style="@style/photo_post_text"
android:id="@+id/photo_post_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="demotext"
/>
<ImageView
android:id="@+id/userimage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="@drawable/pi"
/>
最佳答案
使用 AsyncTask用于加载您的图片。只要您在 UI 线程中执行此类任务,滚动就不会流畅。
看看this tutorial .它将帮助您了解需要实现什么,而无需额外的库。另外请记住,在您滚动时,行一直在重新绘制,加载没有真正的“完成”。您还可以考虑图像缓存,例如用ConcurrentHashMap您可以在其中放置加载的图片。
关于android - ListView 滚动不流畅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20054465/