Android 如何在我的活动底部显示listview?listview上方有3个线性布局

Android 如何在我的活动底部显示listview?listview上方有3个线性布局,android,Android,我将我的android屏幕分成四个垂直部分,我想在屏幕底部显示listview,但每当我将它放在底部时,它就不会与底部对齐。即使我把它拉伸到底部,它也需要全屏。如何做到这一点?您可以通过以下设计在底部显示listview <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" andr

我将我的android屏幕分成四个垂直部分,我想在屏幕底部显示listview,但每当我将它放在底部时,它就不会与底部对齐。即使我把它拉伸到底部,它也需要全屏。如何做到这一点?

您可以通过以下设计在底部显示listview

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <!--First Part--> 

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <!--Second Part-->

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <!--Third Part-->

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <!--Fourth Part-->
        <ListView
            android:id="@+id/xListView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    </LinearLayout>

</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="wrap_content"
android:weightSum="4"
android:orientation="vertical"
>
 <LinearLayout
   android:layout_width="match_parent"
   android:layout_weight="1"
   android:layout_height="0dp">
    //first view....
 </LinearLayout>

<LinearLayout
  android:layout_width="match_parent"
  android:layout_weight="1"
  android:layout_height="0dp">
  //second view....
  </LinearLayout>

<LinearLayout
   android:layout_width="match_parent"
   android:layout_weight="1"
   android:layout_height="0dp">
   //third view....
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:layout_height="0dp">
    //List view goes here....
 </LinearLayout>

如果要在底部显示的listview始终需要显示,则应使用rlativelayout。通过在listview中使用此属性android:layout\u alignParentBottom=true,它将帮助您将其正确放置在底部。

具有垂直方向的线性布局将比 相对布局

<?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="wrap_content"
android:weightSum="4"
android:orientation="vertical"
>
 <LinearLayout
   android:layout_width="match_parent"
   android:layout_weight="1"
   android:layout_height="0dp">
 </LinearLayout>

<LinearLayout
  android:layout_width="match_parent"
  android:layout_weight="1"
  android:layout_height="0dp">
  </LinearLayout>

<LinearLayout
   android:layout_width="match_parent"
   android:layout_weight="1"
   android:layout_height="0dp">
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:layout_height="0dp">

    <ListView
        android:id="@+id/mListView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
 </LinearLayout>

将weightSum与LinearLayout一起使用..将代码放在此处使用代码更新问题。