2016-07-30 37 views
0

如何在照片中實現此佈局?佈局高度取決於設備屏幕

Layout

http://i.stack.imgur.com/5S7cH.png

<RelativeLayout > 
    <LinearLayout android:id="@+id/redlayout"></LinearLayout> 


     <LinearLayout android:orientation="vertical" android:id="@+id/yellowlayout"> 
       <LinearLayout android:id="@+id/yellowchild1"></LinearLayout> 
       <LinearLayout android:id="@+id/yellowchild2"></LinearLayout> 
       <LinearLayout android:id="@+id/yellowchild3"></LinearLayout> 
       <LinearLayout android:id="@+id/yellowchild4"></LinearLayout> 
     </LinearLayout> 


    <LinearLayout android:id="@+id/bluelayout"></LinearLayout> 


</RelativeLayout> 

yellowchilds佈局高度將取決於yellowlayout的高度。

+0

退房'機器人:layout_weithgt' https://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html#attr_android:layout_weight – mljli

回答

0

使用layout_weight財產。

<LinearLayout 
    android:id="@+id/mainLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

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

    <LinearLayout 
     android:id="@+id/yellowLayout" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.7" 
     > 

     <LinearLayout 
      android:id="@+id/yellowChild1" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      /> 
     <LinearLayout 
      android:id="@+id/yellowChild2" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      /> 
     <LinearLayout 
      android:id="@+id/yellowChild3" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      /> 
     <LinearLayout 
      android:id="@+id/yellowChild4" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      /> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/blueLayout" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.2" 
     /> 

</LinearLayout> 
0

由於您的紅色,黃色和藍色佈局都具有百分比屏幕高度,我建議您將根佈局設置爲LinearLayout而不是RelativeLayout。在那裏,您可以分別將android:layout_weight的值提供給1,7和2以分別顯示紅色,黃色和藍色佈局。在yellowLayout內,只需給每個孩子一個android:layout_weight=1值就可以了。

0

嘗試使用佈局權重是這樣的:

<LinearLayout vertical orientation> 
    <LinearLayout layout_weight=0.1> //red 
    <LinearLayout layout_weight=0.175> //yellow 
    <LinearLayout layout_weight=0.175> //yellow 
    <LinearLayout layout_weight=0.175> //yellow 
    <LinearLayout layout_weight=0.175> //yellow 
    <LinearLayout layout_weight=0.2> //blue 
</LinearLayout> 
0

<LinearLayout 
    android:id="@+id/redlayout" 
    android:layout_weight="0.1"/> 

    <LinearLayout 
     android:id="@+id/yellowlayout" 
     android:orientation="vertical" 
     android:layout_weight="0.7"> 

      <LinearLayout 
       android:id="@+id/yellowchild1" 
       android:layout_weight="0.25"/> 

      <LinearLayout 
       android:id="@+id/yellowchild2" 
       android:layout_weight="0.25"/> 

      <LinearLayout 
       android:id="@+id/yellowchild3" 
       android:layout_weight="0.25"/> 

      <LinearLayout 
       android:id="@+id/yellowchild4" 
       android:layout_weight="0.25"/> 

    </LinearLayout> 

<LinearLayout 
    android:id="@+id/bluelayout" 
    android:layout_weight="0.2"/> 

這將使它就像你的要求,並且將擴展在不同的屏幕尺寸。

0

使用此代碼簡單地用任何變化,你可以得到一個完美的結果你想要的.....

<LinearLayout 
 
android:orientation="vertical" 
 
android:layout_width="match_parent" 
 
android:layout_height="match_parent" 
 
> 
 
\t <LinearLayout 
 
\t \t android:id="@+id/redlayout" 
 
\t \t android:background="#64759" 
 
\t \t android:layout_wight="1"; 
 
\t \t android:layout_width="match_parent" 
 
\t \t android:layout_height="0dp" 
 

 
\t ></LinearLayout> 
 

 

 
     <LinearLayout 
 
\t \t android:id="@+id/yellowlayout" 
 
\t \t android:background="#ffff66" 
 
\t \t android:layout_wight="1"; 
 
\t \t android:layout_width="match_parent" 
 
\t \t android:layout_height="0dp" 
 
\t \t > 
 
       <LinearLayout 
 
\t \t \t android:id="@+id/yellowchild1" 
 
\t \t \t android:layout_wight="1"; 
 
\t \t \t android:layout_width="match_parent" 
 
\t \t \t android:layout_height="0dp" 
 
\t \t ></LinearLayout> 
 
       <LinearLayout 
 
\t \t \t android:id="@+id/yellowchild2" 
 
\t \t \t android:layout_wight="1"; 
 
\t \t \t android:layout_width="match_parent" 
 
\t \t \t android:layout_height="0dp" 
 
\t \t ></LinearLayout> 
 
       <LinearLayout 
 
\t \t \t android:id="@+id/yellowchild3" 
 
\t \t \t android:layout_wight="1"; 
 
\t \t \t android:layout_width="match_parent" 
 
\t \t \t android:layout_height="0dp" 
 
\t \t ></LinearLayout> 
 
       <LinearLayout 
 
\t \t \t android:id="@+id/yellowchild4" 
 
\t \t \t android:layout_wight="1"; 
 
\t \t \t android:layout_width="match_parent" 
 
\t \t \t android:layout_height="0dp" 
 
\t \t ></LinearLayout> 
 
     </LinearLayout> 
 

 
\t <LinearLayout 
 
\t \t android:id="@+id/bluelayout" 
 
\t \t android:background="#800080" 
 
\t \t android:layout_wight="1"; 
 
\t \t android:layout_width="match_parent" 
 
\t \t android:layout_height="0dp" 
 
\t ></LinearLayout> 
 

 

 
</LinearLayout>

相關問題