2012-03-08 13 views
5

私は警告を得る:"Nested weights are bad for performance"。私は文字通り別のレイアウトからこのコードをコピーしましたが、このコードではエラーが発生し、もう1つではエラーは発生しません。リニアレイアウトのネストされたウェイト

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

私はそれはばかげたエラーだと思うが、誰かが間違っていることを指摘できますか?

+0

何が問題なのですか? – njzk2

+0

このエラーが発生した行はありますか? –

+0

投稿したレイアウトが正しいです。私はそれに誤りがあるとは思わない。 Eclipseにまだそれがあると表示される場合は、プロジェクトをクリーニングしてみてください。 –

答えて

6

あなたがのLinearLayoutにweightSumを追加し、リストビューの重量を削除する必要があります覚えて

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

これは確かに問題でしたありがとうございました。 –

3

3つの事:

  • はアンドロイドを設定します。0dp」への子どものlayout_widthを"

  • 親のアンドロイド:体重を設定してください

  • は各子供のandroid:layout_weightを比例して設定します(例: weightSum = "5"、3人の子供: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" > 

レイアウトのパフォーマンスが低下するネストされた体重の問題を無視するように、この行を追加します。 。

1

誰でもNestedWeightsを無視したい場合は、ヘッダーにツールを指定する必要があることに注意してください。たとえば、

<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

それは働いた。ありがとう –