2016-07-30 61 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>

相关问题