2016-06-24 11 views
0

レイアウト内の1つの要素が残りの空き領域をすべて占有するのは、常に問題がありました。最後に覚えているのは、match_parentlayout_weightの属性が必要でした。しかし、今日私はこれをして、それは動作します。 e。最初の項目は、ラップされ、すべての残りのスペース全体で二スパンさ:LinearLayout:match_parentアイテムのみがすべての空き領域を占めることは保証されますか?

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     > 

     <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

     </android.support.design.widget.AppBarLayout> 

     <TextView 
      android:id="@+id/view" 
      android:background="#FF80FF00" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"/> 
</LinearLayout> 

問題は、それが(設計によって)保証されていますかどうか、またはそれが、この中に私がそれを望むように働いているという単なる偶然だ場合特定の場合(すなわち、依拠することはできません)。

答えて

1

LinearLayoutの残りのスペースを1つのViewに保存させる保証された方法は、layout_weight値を1に設定し、他の子ビューのweight属性を空のままにします。

次のxmlの例では、2番目の子ビューは、トップビューとボトムビューの間の残りのスペースをすべて占有します。

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

 

 
    <View 
 
     android:layout_width="match_parent" 
 
     android:layout_height="50dp" 
 
     /> 
 

 
    <View 
 
     android:layout_width="match_parent" 
 
     android:layout_height="0dp" 
 
     android:layout_weight="1" 
 
     /> 
 

 
    <View 
 
     android:layout_width="match_parent" 
 
     android:layout_height="50dp" 
 
     /> 
 

 
</LinearLayout>

関連する問題