2012-03-08 12 views
5

Viene visualizzato un messaggio di avviso: "Nested weights are bad for performance". Ho letteralmente copiato questo codice da un altro layout, ma in questo dà un errore e nell'altro non lo fa.peso annidato in layout lineare

<?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> 

Scommetto che è uno stupido errore ma qualcuno può far notare per favore cosa sto facendo male?

+0

qual è il problema? – njzk2

+0

Su quale riga si ottiene questo errore? –

+0

Il layout che hai postato è corretto. Non penso ci sia un errore su di esso. Se Eclipse dice ancora che ce n'è uno, prova a pulire il progetto. –

risposta

6

È necessario aggiungere weightSum al LinearLayout e rimuovere il peso del listview:

<?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

Questo era il problema in effetti grazie. –

3

3 cose da ricordare:

  • impostare l'androide: layout_width dei bambini a "0DP "

  • impostare l'androide: weightSum del genitore

  • imposta l'android: layout_weight di ogni bambino in modo proporzionale (ad es. weightSum = "5", tre figli: 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" > 

Aggiungere questa linea di ignorare problema nidificati peso che riducono le prestazioni del layout di .

1

Se qualcun altro desidera ignorare NestedWeights, tenere presente che è necessario specificare gli strumenti nell'intestazione. Ad esempio

<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

Ha funzionato. Grazie –