2016-06-28 7 views
1

私は3つのセクションを画面に表示しようとしています。スクリーンの10%を占めるトップ "ツールバー" - 素敵なもの。後で塗りつぶすデータは画面の70%を占め、最終的に画面の20%を下部の検索バーに表示します。Layout_Weight予期しない結果を与える

これは簡単なことです:3つの線形レイアウトの子供がそれぞれ0.1,0.7、および0.2の重みを持つ線形レイアウトです。しかし、それは動作していません。一部のビューのlayout_weightを変更すると、他のビューが使用する画面の量が変更されます。ここで私が持っているコードは、現時点でです:

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

<LinearLayout 
    android:id="@+id/linearLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="0.95" 
    android:orientation="horizontal"> 

</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="0.2" 
    android:orientation="horizontal"> 

</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:background="@android:color/transparent" 
    > 

</LinearLayout> 

</LinearLayout> 

は、これは私に(はい、0.95重量で)、第二の空のレイアウトはの80%を占め、画面の20%を占める最初の空のレイアウトを提供します最終レイアウトは空です。最終的なレイアウトに、例えば0.1の重み付けをすると、最初のレイアウトに少し余裕ができます。私は不正なフォーマットをしていると思います。 layout_weight documentationから

答えて

0

この属性は、それが画面に占める必要がありますどのくらいのスペースの点ではビューに「重要度」の値を割り当てます。重み値を大きくすると、親ビューの残りのスペースを埋めるように展開できます。

つまり、レイアウトに必要な残りの領域の割合を示します。
これらの割合でスペースを配布したくない場合は、最初にLinearLayoutsに高さ0を割り当てる必要があります(すべての画面が空きスペースであることを示します)。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical"> 

    <LinearLayout 
     android:id="@+id/linearLayout" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.1" 
     android:orientation="horizontal"> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.7" 
     android:orientation="horizontal"> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.2" 
     android:background="@android:color/transparent"> 

    </LinearLayout> 

</LinearLayout> 
+0

私は読むことが必要です –