1

マイ アクティビティには、カスタム タイトル バーと 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"/>

4

2 に答える 2

0

興味があったので、NPR ニュース アプリをインストールして、バグを再現しました。

私が理解していることから、彼らはアダプターでWebからビットマップをキャッシュしており、キャッシュがそれらのビットマップを再度ダウンロードする必要があるときはいつでも(何らかの理由で)ハングします。問題は、連続スクロール イベントでは、一度に複数のリスト アイテムをスクロールすることが期待されるため、1 つのアイテムがキャッシュされた値を更新する必要がある場合、他のアイテムもそれを必要とする可能性が高いということです。アダプターの実装によっては、奇妙な同時変更が発生する場合があります。

ハングしたときに何が起こるかのトレースを次に示します。アダプターは非常に混乱しています。

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

私の提案: プレースホルダーを使用しますか? アダプターがキャッシュからのみフェッチし、プレースホルダーが見つからない場合はプレースホルダーを取得し、キャッシュが無効な場合はバックグラウンド スレッド操作をトリガーします。

于 2011-05-21T07:13:34.460 に答える
0

すべてのレイアウトの問題に DroidDraw を使用してみてください。Android レイアウトを作成するためのドラッグ アンド ドロップ デスクトップ アプリです。レイアウトにこだわるときはいつもそれを使用します。Tablelayoutそして、レイアウトで使用し、ボタンとリストを に配置する必要があると思いますTablerow

これは、1 つのボタンとリストビューを使用してアプリ用に作成したサンプル レイアウトです。

<?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>
于 2011-05-21T07:32:05.797 に答える