<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>
这是我的 Xml 我想在相对布局中显示 4 个布局 有 4 个 View Listview,Linarlayout,relativelayout 然后是 Textview 我想显示 10 个中的我想显示 listview 2 部分,然后是 linarlayout 1 水平部分和然后是相对布局 6 部分,然后是最后一个 textview 1 部分,每个部分垂直但在我应用下面的每个项目时无法显示,请查看我的代码,我在哪里做错了。
最佳答案
尝试为您的 ListView 设置一个特定的高度。您应该避免在 ListView 上设置 wrap_content 并且有很多在线资源提到了原因。这是输出您期望的结果的布局 xml 的修改版本
<?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>
输出
关于android - 如何在android中的相对布局内将每个布局设置在另一个布局下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35933455/