在Android布局中显示3个同等高度的可滚动列表视图 我试图在一个屏幕上显示我的Android布局中的三个不同的垂直部分,每个屏幕占据屏幕的三分之一,一个在顶部,一个在中间,一个在底部。每个部分都有一个文本视图和一个列表视图,并且列表视图可以滚动以查看所有项目,但整个页面不会移动。我曾尝试将每个TextView和ListView放在LinearLayout中,并将每个LinearLayout的高度设置为屏幕总高度的三分之一,但第一个ListView只显示其中的所有项目,占据了大部分屏幕,其他部分被按下。我还尝试使用布局权重,但由于某些原因,它不起作用。(编辑:设置layout\u weight=“1”最终起作用,我不确定我第一次做错了什么)我如何才能做到这一点,或者有更好的方法吗?

在Android布局中显示3个同等高度的可滚动列表视图 我试图在一个屏幕上显示我的Android布局中的三个不同的垂直部分,每个屏幕占据屏幕的三分之一,一个在顶部,一个在中间,一个在底部。每个部分都有一个文本视图和一个列表视图,并且列表视图可以滚动以查看所有项目,但整个页面不会移动。我曾尝试将每个TextView和ListView放在LinearLayout中,并将每个LinearLayout的高度设置为屏幕总高度的三分之一,但第一个ListView只显示其中的所有项目,占据了大部分屏幕,其他部分被按下。我还尝试使用布局权重,但由于某些原因,它不起作用。(编辑:设置layout\u weight=“1”最终起作用,我不确定我第一次做错了什么)我如何才能做到这一点,或者有更好的方法吗?,android,android-layout,android-listview,android-linearlayout,Android,Android Layout,Android Listview,Android Linearlayout,使用以下方法: <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <ListView android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent"

使用以下方法:

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

  <ListView android:layout_width="0dp" android:layout_weight="1" 
    android:layout_height="match_parent" android:background="#FF0000"/>

  <ListView android:layout_width="0dp" android:layout_weight="1" 
    android:layout_height="match_parent" android:background="#00FF00">

  <ListView android:layout_width="0dp" android:layout_weight="1" 
    android:layout_height="match_parent" android:background="#0000FF">

</LinearLayout>
<?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="horizontal"
    android:weightSum="3">

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="#ff89ff91">


        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="#1"
            android:id="@+id/textView"
            android:padding="5dp"
            android:gravity="center" />

        <ListView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/listView"
            android:layout_below="@+id/textView" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="#ffff8177">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="#2"
            android:id="@+id/textView2"
            android:padding="5dp"
            android:gravity="center" />

        <ListView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/listView2"
            android:layout_below="@+id/textView2" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="#ffffe85d">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="#3"
            android:id="@+id/textView3"
            android:padding="5dp"
            android:gravity="center" />

        <ListView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/listView3"
            android:layout_below="@+id/textView3" />
    </RelativeLayout>
</LinearLayout>


谢谢,这很有效;最初我试过使用砝码,但由于某种原因它不起作用,尽管这种方法确实起作用!
<?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="horizontal"
    android:weightSum="3">

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="#ff89ff91">


        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="#1"
            android:id="@+id/textView"
            android:padding="5dp"
            android:gravity="center" />

        <ListView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/listView"
            android:layout_below="@+id/textView" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="#ffff8177">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="#2"
            android:id="@+id/textView2"
            android:padding="5dp"
            android:gravity="center" />

        <ListView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/listView2"
            android:layout_below="@+id/textView2" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="#ffffe85d">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="#3"
            android:id="@+id/textView3"
            android:padding="5dp"
            android:gravity="center" />

        <ListView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/listView3"
            android:layout_below="@+id/textView3" />
    </RelativeLayout>
</LinearLayout>