2012-03-08 13 views
5

Aparece una advertencia que dice: "Nested weights are bad for performance". Literalmente copié este código de otro diseño, pero en este da un error y en el otro no.peso anidado en diseño lineal

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ListView 
     android:id="@+id/listWeighings_weighing" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_marginBottom="5dp" 
     android:layout_weight="1" 
     android:background="#000000" > 
    </ListView> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <Button 
      android:id="@+id/btnInsertMutation_weighing" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="50" 
      android:text="Mutatie invoeren" /> 

     <Button 
      android:id="@+id/btnExecuteWeighing_weighing" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="50" 
      android:text="weging uitvoeren" /> 
    </LinearLayout> 

</LinearLayout> 

Apuesto a que es un error estúpido, pero ¿alguien puede señalar lo que estoy haciendo mal?

+0

¿cuál es el problema? – njzk2

+0

¿En qué fila obtiene este error? –

+0

El diseño que publicó es correcto. No creo que haya un error en eso. Si Eclipse aún dice que hay uno, intente limpiar el proyecto. –

Respuesta

6

hay que añadir weightSum a la LinearLayout y quitar el peso de la vista de lista:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ListView 
     android:id="@+id/listWeighings_weighing" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_marginBottom="5dp" 
     android:background="#000000" > 
    </ListView> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="100" > 

     <Button 
      android:id="@+id/btnInsertMutation_weighing" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="50" 
      android:text="Mutatie invoeren" /> 

     <Button 
      android:id="@+id/btnExecuteWeighing_weighing" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="50" 
      android:text="weging uitvoeren" /> 
    </LinearLayout> 

</LinearLayout> 
+0

Este fue el problema de hecho gracias. –

3

3 cosas para recordar:

  • establecer el androide: layout_width de los niños a "0DP "

  • establecer el androide: weightSum del padre

  • establece el android: layout_weight de cada niño proporcionalmente (p. weightSum = "5", tres hijos: layout_weight = "1", layout_weight = "3", layout_weight = "1")
0
<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:background="@color/black" 
    android:orientation="horizontal" 
    tools:ignore="NestedWeights" > 

Añadir esta línea de ignorar un problema anidada peso que reducen el rendimiento de diseño .

1

Si alguien más desea ignorar NestedWeights, tenga en cuenta que también debe especificar las herramientas en el encabezado. Por ejemplo

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@color/appDarkBackGround" 
android:orientation="horizontal" 
tools:context=".MainActivity" 
tools:ignore="NestedWeights" 
> 
+0

Funcionó. Gracias –

Cuestiones relacionadas