列表视图滚动不平滑 [英] List View Scroll Not Smooth

查看:141
本文介绍了列表视图滚动不平滑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义列表视图,它显示的用户,并有照片 我检索API的数据,这给了JSON输出,

我的问题是,列表视图不滚动顺利,它挂的秒和卷轴,它重复相同的,直到我们到达终点。

我想它可能我,因为我是在UI线程上运行的网络相关的操作,但它仍然这样做,它完成加载,即使?

我的自定义列表视图的结构

 < TextView的风格=@风格/ photo_post_text
             机器人:ID =@ + ID / photo_post_text
             机器人:layout_width =match_parent
             机器人:layout_height =WRAP_CONTENT
             机器人:文本=demotext
           />


        < ImageView的
            机器人:ID =@ + ID / userimage
           机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:scaleType =fitXY

            机器人:adjustViewBounds =真
           机器人:SRC =@可绘制/ PI
           />
 

解决方案

使用的 AsyncTask的为您的图片加载。滚动不会,只要你在UI线程做这样的工作顺利。

看一看本教程。这将帮助你了解你需要什么没有额外的库需要执行。也请记住,该行被重画所有的时间,而您滚动,有没有真正的整理负载。你还可以考虑的图像缓存,如以<一href="http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentHashMap.html">ConcurrentHashMap在其中,你可以把你装的照片。

i have a custom list view, which displays users, and there photos i retrieve the data from API, Which gives JSON Output,

My Issue is that the list view is not scrolling smoothly, it hangs for a sec and scrolls, it repeats the same till we reach the end.

i thought it might me because i am running network related operation on the UI thread, but it continues to do that even after it completes loading?

the structure of my custom Listview is

 <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" 
           />

解决方案

Use an AsyncTask for the loading of your pictures. The scrolling will not be smooth as long as you do such tasks in the UI thread.

Have a look at this tutorial. It will help you understand what you need to implement without the need of additional libraries. Also please keep in mind that the rows are redrawn all the time while you scroll, there's no real "finishing" of loading. You can additionally consider an image-cache, e.g. with a ConcurrentHashMap in which you could put your loaded pictures.

这篇关于列表视图滚动不平滑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆