如何在android的相对布局中,将每个布局设置在另一个布局的下方

如何在android的相对布局中,将每个布局设置在另一个布局的下方,android,Android,这是我的Xml我想在相对布局中显示4个布局有4个视图Listview、Linarlayout、relativelayout和Textview我想显示10个视图中的10个我想显示Listview 2部分,然后直线水平布局1个部分,然后相对布局6个部分,最后一个文本视图1个部分,每个部分垂直,但无法显示,而我已应用了下面的每个项目请查看我的代码,我犯了错误的地方 尝试为列表视图设置特定高度。您应该避免在列表视图上设置wrap_内容,并且有很多在线资源提到了原因。这里是布局xml的修改版本,它输出您期

这是我的Xml我想在相对布局中显示4个布局有4个视图Listview、Linarlayout、relativelayout和Textview我想显示10个视图中的10个我想显示Listview 2部分,然后直线水平布局1个部分,然后相对布局6个部分,最后一个文本视图1个部分,每个部分垂直,但无法显示,而我已应用了下面的每个项目请查看我的代码,我犯了错误的地方

尝试为列表视图设置特定高度。您应该避免在列表视图上设置wrap_内容,并且有很多在线资源提到了原因。这里是布局xml的修改版本,它输出您期望的结果

 <RelativeLayout
        android:id="@+id/content"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/footer"
        android:gravity="center">


        <ListView
            android:id="@+id/gridView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"



            />


        <LinearLayout
            android:id="@+id/linearalyout1"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/gridView"
            android:padding="5dp"
            android:background="#0070c0"
            android:orientation="horizontal"
            android:gravity="center_vertical"
            android:layout_weight=".05"
            >

            <ImageView
                android:id="@+id/acceptbutton"
                android:layout_width="32dp"
                android:layout_height="32dp"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:layout_marginTop="5dp"
                android:background="@mipmap/accept_icon" />


            <View

                android:layout_width="1dp"
                android:layout_height="wrap_content"
                android:background="#cfcfcf" />

            <ImageView
                android:id="@+id/cplacereached"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:layout_marginTop="5dp"
                android:background="@mipmap/map_icon"/>



            <View

                android:layout_width="1dp"
                android:layout_height="wrap_content"
                android:background="#cfcfcf" />

            <ImageView
                android:id="@+id/dataentry"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:layout_marginTop="5dp"
                android:background="@mipmap/dataentry_icon"
                />


        </LinearLayout>

        <RelativeLayout
            android:id="@+id/fraghome_map"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:layout_below="@+id/linearalyout1">

        </RelativeLayout>


        <TextView
            android:id="@+id/tv_distance_time"
            android:layout_width="fill_parent"
            android:layout_height="20dp"
            android:layout_alignParentTop="true"
            android:layout_below="@+id/fraghome_map"
            android:text="151121321"
            android:textSize="20dp"
            android:textStyle="bold" />

    </RelativeLayout>

输出


您是否有一份您希望视图看起来如何的草图?是的,等等,我会给您另外请注意,制作ListView
wrap\u内容
不会有任何效果。您必须在dp中指定一个高度,否则它将占据其父容器的整个高度。在您的代码中,一切正常,但只需在文本视图中删除android:layout\u alignParentTop=“true”。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <ListView
        android:id="@+id/gridView"
        android:layout_width="match_parent"
        android:layout_height="150dp" />


    <LinearLayout
        android:id="@+id/linearalyout1"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/gridView"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:weightSum="10">

        <ImageView
            android:id="@+id/acceptbutton"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2.5"
            android:background="#2a7fff" />


        <View
            android:layout_width="1dp"
            android:layout_height="wrap_content"
            android:background="#cfcfcf" />

        <ImageView
            android:id="@+id/cplacereached"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3.5"
            android:background="#fa3a3a" />


        <View

            android:layout_width="1dp"
            android:layout_height="wrap_content"
            android:background="#cfcfcf" />

        <ImageView
            android:id="@+id/dataentry"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="4"
            android:background="#7dea58" />


    </LinearLayout>

    <RelativeLayout
        android:id="@+id/fraghome_map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/tv_distance_time"
        android:layout_below="@+id/linearalyout1"
        android:background="#f594df">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="You Map Fragment Here" />

    </RelativeLayout>


    <TextView
        android:id="@+id/tv_distance_time"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="20dp"
        android:padding="10dp"
        android:layout_alignParentBottom="true"
        android:gravity="center_vertical"
        android:text="Bottom Text"
        android:textSize="20dp"
        android:textStyle="bold" />

</RelativeLayout>