Reputation: 2365
I'm creating an android application, which has a particular screen (layout) with over (120+ views), which generates the warning:
"main.xml has more than 80 views, bad for performance"
I have lots of TextViews
, EditTexts
, groups of RadioButtons
organized on 26 TableRows
.
Is there anything I can do to enhance application performance and remove warning?
source: main.xml_capture
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout00"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<TableRow
android:id="@+id/tableRow00"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right|top"
android:gravity="right" >
<Button
android:id="@+id/id_but_val"
android:layout_width="@dimen/button_width"
android:layout_height="wrap_content"
android:background="@drawable/button_colored"
android:text="@string/but_valid"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/id_but_up"
android:layout_width="@dimen/button_width"
android:layout_height="wrap_content"
android:background="@drawable/button_colored"
android:onClick="goToTop"
android:text="@string/but_ret_up"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/id_but_back"
android:layout_width="@dimen/button_width"
android:layout_height="wrap_content"
android:background="@drawable/button_colored"
android:text="@string/but_ret_back"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<ScrollView
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="true"
android:overScrollMode="always"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="outsideInset" >
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<TableRow
android:id="@+id/TableRow01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/row_margin_top" >
<TextView
android:id="@+id/TextView01"
android:layout_width="@dimen/label_width"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/view_left_margin"
android:text="@string/ecran3_84_obstacles_acces" />
<RadioGroup
android:id="@+id/RadioGroup01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/view_left_margin"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/RadioButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radio_value_oui" />
<RadioButton
android:id="@+id/RadioButton02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radio_value_non" />
</RadioGroup>
</TableRow>
<TableRow
android:id="@+id/TableRow02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/row_margin_top" >
<TextView
android:id="@+id/TextView02"
android:layout_width="@dimen/label_width"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/view_left_margin"
android:text="@string/ecran3_85_limit_tonnage" />
<EditText
android:id="@+id/EditText01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/view_left_margin"
android:ems="@string/editTextEms"
android:inputType="numberDecimal" />
</TableRow>
<TableRow
android:id="@+id/TableRow03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/row_margin_top"
android:visibility="gone" >
<TextView
android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/view_left_margin"
android:text="@string/ecran3_86_derog" />
</TableRow>
<TableRow
android:id="@+id/TableRow04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/row_margin_top" >
<TextView
android:id="@+id/TextView04"
android:layout_width="@dimen/label_width"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/view_left_margin"
android:text="@string/ecran3_87_limit_hauteur" />
<EditText
android:id="@+id/EditText03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/view_left_margin"
android:ems="@string/editTextEms"
android:inputType="numberDecimal" />
</TableRow>
<TableRow
android:id="@+id/TableRow05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/row_margin_top" >
<TextView
android:id="@+id/TextView05"
android:layout_width="@dimen/label_width"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/view_left_margin"
android:text="@string/ecran3_88_limit_largeur" />
<EditText
android:id="@+id/EditText04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/view_left_margin"
android:ems="@string/editTextEms"
android:inputType="numberDecimal" />
</TableRow>
<TableRow
android:id="@+id/TableRow06"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/row_margin_top" >
<TextView
android:id="@+id/TextView06"
android:layout_width="@dimen/label_width"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/view_left_margin"
android:text="@string/ecran3_89_trav_jour" />
<RadioGroup
android:id="@+id/RadioGroup06"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/view_left_margin"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/RadioButton11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radio_value_oui" />
<RadioButton
android:id="@+id/RadioButton12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radio_value_non" />
</RadioGroup>
</TableRow>
<TableRow
android:id="@+id/TableRow07"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/row_margin_top" >
<TextView
android:id="@+id/TextView07"
android:layout_width="@dimen/label_width"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/view_left_margin"
android:text="@string/ecran3_90_acces_intemperies" />
<RadioGroup
android:id="@+id/RadioGroup07"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/view_left_margin"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/RadioButton13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radio_value_oui" />
<RadioButton
android:id="@+id/RadioButton14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radio_value_non" />
</RadioGroup>
</TableRow>
<TableRow
android:id="@+id/TableRow08"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/row_margin_top" >
<TextView
android:id="@+id/TextView08"
android:layout_width="@dimen/label_width"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/view_left_margin"
android:text="@string/ecran3_91_acces_de_client" />
<RadioGroup
android:id="@+id/RadioGroup08"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/view_left_margin"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/RadioButton15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radio_value_oui" />
<RadioButton
android:id="@+id/RadioButton16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radio_value_non" />
</RadioGroup>
</TableRow>
<LinearLayout
android:id="@+id/LinearLayout02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TableRow
android:id="@+id/TableRow09"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/row_margin_top" >
<TextView
android:id="@+id/TextView09"
android:layout_width="@dimen/label_width"
android:layout_height="fill_parent"
android:layout_marginLeft="@dimen/view_left_margin"
android:text="@string/ecran3_92_contraintes_reservoir" />
<EditText
android:id="@+id/EditText05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/view_left_margin"
android:ems="@string/editTextEms"
android:inputType="text" />
</TableRow>
<TableRow
android:id="@+id/TableRow10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/row_margin_top" >
<TextView
android:id="@+id/TextView10"
android:layout_width="@dimen/label_width"
android:layout_height="fill_parent"
android:layout_marginLeft="@dimen/view_left_margin"
android:text="@string/ecran3_93_dalle_pret" />
<RadioGroup
android:id="@+id/RadioGroup10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/view_left_margin"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/RadioButton19"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radio_value_oui" />
<RadioButton
android:id="@+id/RadioButton20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radio_value_non" />
</RadioGroup>
</TableRow>
<!-- TableRow10 to TableRow26 -->
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Upvotes: 5
Views: 5339
Reputation: 87064
Without seeing your full layout I would say to replace that TableLayout
with a ListView
.
I'm guessing that you have a number of Views
for each row, if you switch to a ListView
you'll avoid the need to load the entire layout in memory, instead you'll load only the visible rows on the screen of the ListView
+ any views you have besides that.
With the above approach, you'll be able to remove a substantial number of rows from the current layout.
EDIT :
Based on your added layout, some advices:
TableRow
can be used as a normal view in a layout but its main purpose it to be a child of a TableLayout
.Buttons
from tableRow00
to have equal width then you can make a small improvement and instead of your current layout, replace LinearLayout00
with a RelativeLayout
, remove the tableRow00
and then place the Buttons
and the ScrollView
using the rules of RelativeLayout
.LinearLayout01
with a TableLayout
.LinearLayout02
(I'm guessing all of your rows are the same?!) but you should remove it and directly append TableRow09
- TableRow26
to LinearLayout01
.Upvotes: 2