Android4.1.2。私にはLinearLayout
子供ListView
がいます。このリストビューに20行を追加し、3つのコントロールを備えたカスタム行レイアウトを使用しTextView
ます。これらの行の半分が表示されているので、残りを表示するにはスクロールする必要があります。問題は、上または下からスクロールを開始すると、アプリが数秒間ハングするように見えることです(中央では問題ないようです)。
使用できる最適化がいくつかあることを理解しています。これまでのところ、私はこれを試しました:
- 私の習慣では、を呼び出さないようにを
ArrayAdapter
使用しています。ViewHolder
findViewById
- では
getView()
、はがのLayoutInflater
場合にのみ使用されconvertView
ますnull
。 getViewTypeCount()
1をgetItemViewType(...)
返し、0を返します。- テキストビューへのすべての呼び出しを削除し
setText()
ますsetColor()
。 - デバッガーを切断します。
リストビューには他にどのようなボトルネックがありますか?
私の行のレイアウト:
<?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秒間ハングします。したがって、前後にスクロールするとアプリがフリーズします。
ここで何が欠けていますか?