列表视图滚动不平滑平滑、视图、列表

2023-09-05 23:04:15 作者:ζ街挽

我有一个自定义列表视图,它显示的用户,并有照片 我检索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线程做这样的工作顺利。

看一看本教程。这将帮助你了解你需要什么没有额外的库需要执行。也请记住,该行被重画所有的时间,而您滚动,有没有真正的整理负载。你还可以考虑的图像缓存,如以ConcurrentHashMap在其中,你可以把你装的照片。

3d中VR视图平滑却仍显示线框怎么回事 如何让他显示成实物,急

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.