布局高度取决于设备屏幕

时间:2016-07-30 13:22:46

标签: android xml layout

如何在照片中实现此布局?

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的高度。

5 个答案:

答案 0 :(得分:0)

由于您的红色,黄色和蓝色布局都具有百分比的屏幕高度,因此我建议您将根布局设为LinearLayout而不是RelativeLayout。在那里,您可以将android:layout_weight值分别提供给红色,黄色和蓝色布局的1,7和2。在yellowLayout内,只需为每个孩子提供android:layout_weight=1值即可。

答案 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>

答案 2 :(得分: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"/>

这就像你要求的那样,并且会扩展到不同的屏幕尺寸。

答案 3 :(得分:0)

使用此代码只需完成任何更改即可获得您想要的完美结果.....

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

	></LinearLayout>


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

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


</LinearLayout>
&#13;
&#13;
&#13;

答案 4 :(得分: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>
相关问题