2

Android4.1.2。私にはLinearLayout子供ListViewがいます。このリストビューに20行を追加し、3つのコントロールを備えたカスタム行レイアウトを使用しTextViewます。これらの行の半分が表示されているので、残りを表示するにはスクロールする必要があります。問題は、上または下からスクロールを開始すると、アプリが数秒間ハングするように見えることです(中央では問題ないようです)。

使用できる最適化がいくつかあることを理解しています。これまでのところ、私はこれを試しました:

  1. 私の習慣では、を呼び出さないようにをArrayAdapter使用しています。ViewHolderfindViewById
  2. ではgetView()、はがのLayoutInflater場合にのみ使用されconvertViewますnull
  3. getViewTypeCount()1をgetItemViewType(...)返し、0を返します。
  4. テキストビューへのすべての呼び出しを削除しsetText()ますsetColor()
  5. デバッガーを切断します。

リストビューには他にどのようなボトルネックがありますか?

私の行のレイアウト:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <TextView
        android:id="@+id/my_text1"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textColor="@android:color/white"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/my_text2"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="4"
        android:ellipsize="end"
        android:textColor="@android:color/white" />

    <TextView
        android:id="@+id/my_text3"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:gravity="right"
        android:textColor="@android:color/white" />
</LinearLayout>

私はその属性を疑ったlayout_weightが、それらを削除しても役に立たなかった!この遅れの問題を修正する別の試みでは、私ListViewはこれらのスタイルを持っています:

<ListView
        android:id="@+id/my_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="3dip"
        android:background="@android:color/transparent"
        android:cacheColorHint="@android:color/transparent"
        android:persistentDrawingCache="scrolling"
        android:scrollingCache="false" />

ご覧のとおり、私はほとんどすべてを試しました。それでも、これらの20行をスクロールすると、上部/下部に到達したときにUIが2〜4秒間ハングします。したがって、前後にスクロールするとアプリがフリーズします。

ここで何が欠けていますか?

4

1 に答える 1

3

考慮すべきもう1つのことは、リストアイテムでのオーバードローの可能性です。これは、デバイスの開発者設定のオプションで表示できます。

一般的なパフォーマンスの問題については、特に、ListViewRomainGuyの「壮大な」記事であるAndroidパフォーマンスのケーススタディのみをお勧めします。オーバードローも1つの大きな問題としてそこで言及されています。

于 2013-01-13T11:51:48.673 に答える