2011-05-21 101 views
1

我的活動有一個自定義標題欄和一個ListView。 ListView使用一個SimpleAdapter來顯示一組數據,沒什麼奇怪的。我注意到,當我不停地滑動手指而不離開屏幕時,通常滾動停止並且滾動條消失。 Gmail收件箱活動中不會發生這種情況。在NPR新聞應用程序中,菜單活動遭受同樣的問題。我錯過了什麼?Android ListView滾動間歇停止

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

+0

似乎是一個Android錯誤的樣品佈局。升級到2.3.4後不再可重現。 – kimkunjj 2011-12-27 01:07:47

回答

0

我很好奇,所以我安裝了NPR新聞應用程序,並得到複製你的錯誤。

從我所瞭解的情況來看,他們在網絡適配器中緩存Bitmaps,並且只要緩存需要再次下載這些位圖(無論什麼原因),它就會掛起。事情是,在持續的滾動事件中,你需要一次滾動多個列表項,所以如果一個項需要刷新它的緩存值,那麼其他項也需要它。根據適配器的實現,可能會發生一些奇怪的併發修改。

下面是它掛起時會發生什麼的痕跡:適配器越來越混亂。

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 

我的建議:使用佔位符?讓適配器只從緩存中獲取,找不到找到的佔位符,並在緩存無效時觸發後臺線程操作。

0

嘗試使用DroidDraw解決所有佈局問題。它是一個拖放桌面應用程序,用於創建android佈局。我總是使用它,只要我堅持佈局。我認爲你應該在你的佈局中使用Tablelayout,並將按鈕和列表放入Tablerow

這裏,我曾我的應用程序創建的一個按鈕和ListView

<?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>