I encounter performances issues while using a RelativeLayout (wrapped into a ScrollView) containing 153 TextView. Each of the TextView has a 9 patch background.
The main layout:
<ScrollView
android:id="@+id/forum_accueil_ScrollView"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="@color/white">
<RelativeLayout android:id="@+id/forum_accueil_RelativeLayout"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="@color/white">
</RelativeLayout>
</ScrollView>
The RelativeLayout is filled with TextViews programmatically (the item count and description comes from a WS). Each of the TextView has a 9patch background selector. TextView description below:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="35dip"
android:textColor="@color/myblue"
android:textStyle="bold"
android:gravity="center_vertical" android:layout_gravity="center_vertical"
android:background="@drawable/selector_forum_accueil_item">
</TextView>
At the end, I have a RelativeLayout containing 153 TextView. The display and scroll is really slow. Even coming back on this activity takes some time.
I opened the Hierarchy viewer and the ScrollView takes the following time to display:
Measure: 28ms
Layout: 1.2ms
Draw: 18ms
Is there a way to speed up the display and the responsiveness? Is a single RelativeLayout containing as much Views is the best way to do it (I tried to flatten as much as possible the hierarchy with this technique)?
I tried removing the 9 patch background for test, it seems much more responsive. Why?
That is an obscene amount of TextViews. At that point use a ListView. What does your RelativeLayout do for you (in this instance) that a ListView can’t?