Is working with weights feasible?

1

I'm setting up a layout here and after including the property: android: layout_weight , eclipse returns a warning: 'nested weights bad for performance'.

Why working with this property is bad for performance? And to what extent, will this influence 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>

    
asked by anonymous 20.06.2014 / 13:56

1 answer

1

This is bad because layout_weight requires the widget to be measured twice when a LinearLayout with weight other than zero is nested in another LinearLayout with weight also nonzero, this exponentially increases the measurements.

An alternative is to use RelativeLayouts and adjust the display according to the places of other views, without the use of specific dpi values.

References:

20.06.2014 / 14:32