How to divide layout to 3 parts?

混江龙づ霸主 提交于 2019-12-01 06:37:24

This will work

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

<LinearLayout
    android:id="@+id/lay1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:background="#ff0000" >

    <TextView
        android:id="@+id/textView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />
</LinearLayout>

<LinearLayout
    android:id="@+id/lay2"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:background="#00ff00" >

    <TextView
        android:id="@+id/TextView02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />
</LinearLayout>

<LinearLayout
    android:id="@+id/lay3"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1" 
    android:background="#0000ff">

    <TextView
        android:id="@+id/TextView03"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />
</LinearLayout>

At first, I didn't realise, that problem was not there. I had ScrollView and it made these layouts not work with weights. I added android:fillViewport="true" to ScrollView and it got fixed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!