android – 在布局上增加超过80个视图的应用程序性能

android – 在布局上增加超过80个视图的应用程序性能,第1张

概述我正在创建一个 Android应用程序,它有一个超过(120个视图)的特定屏幕(布局),它会生成警告: "main.xml has more than 80 views, bad for performance" 我有很多TextViews,EditTexts,在26个TableRows上组织的RadioButtons组. 我有什么办法可以提高应用程序性能并删除警告吗? 资源: main.xml_ 我正在创建一个 Android应用程序,它有一个超过(120个视图)的特定屏幕(布局),它会生成警告:

"main.xml has more than 80 vIEws,bad for performance"

我有很多TextVIEws,EditTexts,在26个tableRows上组织的Radiobuttons组.

我有什么办法可以提高应用程序性能并删除警告吗?

资源:
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>
解决方法 在没有看到完整布局的情况下,我会说用ListVIEw替换tableLayout.
我猜你每行都有很多视图,如果切换到ListVIEw,你将无需在内存中加载整个布局,而是只加载ListVIEw屏幕上的可见行除此之外你有任何观点.

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

编辑:

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

> tableRow可以用作布局中的普通视图,但其主要目的是将其作为tableLayout的子级.>如果你不希望tableRow00的buttons具有相等的宽度,那么你可以做一个小的改进,而不是你当前的布局,用relativeLayout替换linearLayout00,删除tableRow00,然后使用规则放置按钮和ScrollVIEw relativeLayout的.>将linearLayout01替换为tableLayout.>我不知道为什么你添加了linearLayout02(我猜你的所有行都是一样的?!)但你应该删除它并直接将tableRow09 – tableRow26附加到linearLayout01.>我的其余部分仍然存在.

@H_403_44@ 总结

以上是内存溢出为你收集整理的android – 在布局上增加超过80个视图的应用程序性能全部内容,希望文章能够帮你解决android – 在布局上增加超过80个视图的应用程序性能所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1126558.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存