1
I’m mounting a layout here and after include the property: android:layout_weight, the eclipse returns a warning: 'nested Weights bad for performance'.
Why work with this property, is it bad for performance? And to what extent, it will influence performance/performance?
Thank you.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:id="@+id/tv_codProduto"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3" //Advertência aparece aqui
android:text="Código Produto:" />
<TextView
android:id="@+id/tv_descProduto"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.7"
android:text="Descrição:" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1">
<EditText
android:id="@+id/et_codProduto"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3" //Advertência aparece aqui
android:inputType="none"/>
<EditText
android:id="@+id/et_descProduto"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.7"
android:inputType="none"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/tv_complemento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Complemento:"/>
<EditText
android:id="@+id/ed_complemento"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="none"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:id="@+id/tv_qtdeEstoque"
android:layout_weight="0.5" //Advertência aparece aqui
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Estoque:"
android:inputType="none"/>
<TextView
android:id="@+id/tv_vrVenda"
android:layout_weight="0.5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Valor de Venda:"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1">
<EditText
android:id="@+id/ed_qtdeEstoque"
android:layout_width="0dp"
android:layout_weight="0.5" //Advertência aparece aqui
android:layout_height="wrap_content"
android:inputType="none"/>
<EditText
android:id="@+id/ed_vrVenda"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:ems="10" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_fornecedor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Fornecedor:"/>
<EditText
android:id="@+id/ed_fornecedor"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:inputType="none"/>
</LinearLayout>
</LinearLayout>
If the Eclipse returns with this warning is because it is actually bad for performance. I do not know why. What I can say is that in the many layouts I’ve done, I’ve rarely had to use
android:layout_weight
and, as I recall, never in a "nested" way. What this warning may also suggest is that there are other ways to achieve the same objective without the use of nested Weights. If you post the Xml of your layout it may be easier to help you. If not, this question may be considered Too broad– ramaral
@ramaral - Add xml. Thanks for the help.
– emanuelsn