Android 通过布局上的80多个视图提高应用程序性能

Android 通过布局上的80多个视图提高应用程序性能,android,android-layout,Android,Android Layout,我正在创建一个android应用程序,它有一个特定的屏幕(布局),超过120个视图,生成警告: "main.xml has more than 80 views, bad for performance" 我有很多文本视图,编辑文本,单选按钮组组织在26个表格行 我能做些什么来提高应用程序性能和消除警告 资料来源: 在没有看到完整布局的情况下,我想用列表视图替换表格布局。 我猜您每行都有许多视图,如果切换到列表视图,您将避免在内存中加载整个布局,而只加载列表视图屏幕上可见的行+除此之外

我正在创建一个android应用程序,它有一个特定的屏幕(布局),超过120个视图,生成警告:

   "main.xml has more than 80 views, bad for performance"
我有很多
文本视图
编辑文本
单选按钮组
组织在26个
表格行

我能做些什么来提高应用程序性能和消除警告

资料来源:


在没有看到完整布局的情况下,我想用
列表视图
替换
表格布局
。 我猜您每行都有许多
视图
,如果切换到
列表视图
,您将避免在内存中加载整个布局,而只加载
列表视图
屏幕上可见的行+除此之外的任何视图

使用上述方法,您将能够从当前布局中删除大量行

编辑:

根据您添加的布局,提出一些建议:

  • TableRow
    可以用作布局中的常规视图,但其主要用途是作为
    TableLayout
    的子视图
  • 如果您不想让
    表格Row00
    中的
    按钮具有相同的宽度,则可以进行一些小的改进,并用
    相对线布局替换
    线性布局00
    ,移除
    表格Row00
    ,然后使用
    相对性yout
    的规则放置
    按钮
    滚动视图
  • 线性布局01
    替换为
    表格布局
  • 我不知道你为什么要添加
    LinearLayout02
    (我猜你所有的行都是一样的?!)但是你应该删除它并直接将
    TableRow09
    -
    TableRow26
    附加到
    LinearLayout01
  • 我的其余答案仍然存在
尝试某种分页,并将表单拆分为多个活动。我必须将所有表单元素都放在可滚动的容器中,这样分页在5月份就不起作用了。但hintI的thx使用LinearLayout02动态地使其在满足(或不满足)有关输入值的某些条件时可见(或消失)。谢谢你的帮助!
<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>