【问题标题】:Android ListView scrolling intermittantly stopsAndroid ListView 滚动间歇性停止
【发布时间】:2011-05-21 06:38:15
【问题描述】:

我的 Activity 有一个自定义标题栏和一个 ListView。 ListView 使用 SimpleAdapter 显示数据数组,没什么特别的。我注意到,当我在不离开屏幕的情况下继续上下滑动手指时,滚动通常会停止并且滚动条会消失。这在 Gmail 收件箱活动中永远不会发生。在 NPR 新闻应用程序中,菜单活动遇到同样的问题。我错过了什么?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<RelativeLayout android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@android:drawable/title_bar"
    android:singleLine="true"
    android:textAppearance="@android:style/TextAppearance.WindowTitle">

     <Button
        android:id="@+id/accounts_filter" 
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_alignParentRight="true"
        style="@android:style/Widget.Button.Small"
        android:maxWidth="200sp"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:onClick="openFilter"/>

</RelativeLayout>

<ListView android:id="@+id/accounts_list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>

【问题讨论】:

  • 似乎是一个 Android 错误。升级到 2.3.4 后不再重现。

标签: android listview non-scrolling


【解决方案1】:

我很好奇,所以我安装了 NPR 新闻应用并复制了你的错误。

据我了解,他们正在他们的适配器中缓存来自网络的位图,并且只要缓存需要再次下载这些位图(无论出于何种原因),它就会挂起。问题是,在连续滚动事件中,您应该一次滚动浏览多个列表项,因此如果一个项目需要刷新其缓存值,则其他项目很可能也需要它。根据适配器的实现,可能会发生一些奇怪的并发修改。

这是当它挂起时发生的事情的踪迹:适配器变得非常混乱。

05-21 08:53:07.570: DEBUG/org.npr.android.news.ImageThreadLoader(6457): Cache hit: http://media.npr.org/assets/img/2011/05/20/machoman_sq.jpg?t=1305913905&s=12
05-21 08:53:07.580: DEBUG/org.npr.android.util.PlaylistProvider(6457): content://org.npr.android.util.Playlist;story_id = ?;[136497574]
05-21 08:53:07.580: DEBUG/org.npr.android.news.ImageThreadLoader(6457): Cache hit: http://media.npr.org/assets/img/2011/05/20/pelosi_flex.jpg?t=1305924952&s=12
05-21 08:53:07.610: DEBUG/org.npr.android.news.DownloadDrawable(6457): Got bitmap
05-21 08:53:07.610: DEBUG/org.npr.android.news.DownloadDrawable(6457): Download complete
05-21 08:53:07.610: DEBUG/org.npr.android.news.DownloadDrawable(6457): Starting download
05-21 08:53:07.620: DEBUG/org.npr.android.util.PlaylistProvider(6457): content://org.npr.android.util.Playlist;story_id = ?;[136507004]
05-21 08:53:07.620: DEBUG/org.npr.android.news.ImageThreadLoader(6457): Cache hit: http://media.npr.org/assets/img/2011/05/20/capitol.jpg?t=1305929989&s=12
05-21 08:53:07.630: DEBUG/org.npr.android.util.PlaylistProvider(6457): content://org.npr.android.util.Playlist;story_id = ?;[136498068]
05-21 08:53:07.630: DEBUG/org.npr.android.news.ImageThreadLoader(6457): Cache hit: http://media.npr.org/assets/img/2011/05/20/ppw1.jpg?t=1305913144&s=12
05-21 08:53:07.640: DEBUG/org.npr.android.news.ImageThreadLoader(6457): Cache hit: http://media.npr.org/assets/img/2011/05/20/levee.jpg?t=1305901869&s=12
05-21 08:53:07.670: WARN/org.npr.android.news.NewsListAdapter(6457): Could not find list item at position 27
05-21 08:53:07.680: DEBUG/org.npr.android.news.ImageThreadLoader(6457): Cache hit: http://media.npr.org/assets/img/2011/05/20/imf.jpg?t=1305915244&s=12
05-21 08:53:07.710: DEBUG/org.npr.android.news.ImageThreadLoader(6457): Cache hit: http://media.npr.org/assets/img/2011/05/20/syria.jpg?t=1305904814&s=12
05-21 08:53:07.750: DEBUG/org.npr.android.news.ImageThreadLoader(6457): Cache hit: http://media.npr.org/assets/img/2011/05/20/netanyahu.jpg?t=1305900960&s=12
05-21 08:53:07.850: DEBUG/org.npr.android.news.DownloadDrawable(6457): Got bitmap
05-21 08:53:07.850: DEBUG/org.npr.android.news.DownloadDrawable(6457): Download complete
05-21 08:53:07.860: DEBUG/org.npr.android.news.DownloadDrawable(6457): Starting download
05-21 08:53:07.880: WARN/org.npr.android.news.NewsListAdapter(6457): Could not find list item at position 28
05-21 08:53:08.510: DEBUG/org.npr.android.news.DownloadDrawable(6457): Got bitmap
05-21 08:53:08.510: DEBUG/org.npr.android.news.DownloadDrawable(6457): Download complete
05-21 08:53:08.550: WARN/org.npr.android.news.NewsListAdapter(6457): Could not find list item at position 29

我的建议:使用占位符?让适配器仅从缓存中获取,在未找到占位符时检索占位符,并在缓存无效时触发后台线程操作。

【讨论】:

    【解决方案2】:

    尝试使用 DroidDraw 解决所有布局问题。它是一个用于创建 android 布局的拖放桌面应用程序。每当我坚持布局时,我总是使用它。而且我认为您应该在布局中使用Tablelayout,并将按钮和列表放入Tablerow

    这是我用一个按钮和列表视图为我的应用创建的示例布局

    <?xml version="1.0" encoding="utf-8"?>
    
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/apps"
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >
                <TableRow
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" >
                            <Button
                                android:id="@+id/undoApps"
                                android:layout_height="60dip"
                                android:layout_width="320dip"
                                android:text="I AM A BUTTON"
                                android:textSize="22sp"
                                android:textStyle="bold"
                                android:typeface="serif">
                            </Button>
                 </TableRow>
    
                <TableRow
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" >
                    <ListView
                        android:id="@android:id/list"
                        android:layout_height="wrap_content"
                        android:layout_width="wrap_content"
                        android:drawSelectorOnTop="false" >
                    </ListView>
                </TableRow>
       </TableLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-31
      • 2011-09-16
      • 1970-01-01
      • 2011-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多