Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法将线性布局安排为在上方列表视图的底部显示按钮_Android_Xml_Listview - Fatal编程技术网

Android 无法将线性布局安排为在上方列表视图的底部显示按钮

Android 无法将线性布局安排为在上方列表视图的底部显示按钮,android,xml,listview,Android,Xml,Listview,考虑下一段xml- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <LinearLayout xmlns:android="http:

考虑下一段xml-

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:tools="http://schemas.android.com/tools"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             tools:context="com.android.fiby.fragments.MenuFragment"
             android:orientation="vertical"
             android:layout_weight="0.7">

        <com.android.fiby.TitleFont
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp"
            android:textColor="#5e240a"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:textSize="40dp"
            android:text="בדיקה"
            android:id="@+id/list_title"/>

        <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>

    </LinearLayout>

    <LinearLayout android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:visibility="visible"
              android:layout_gravity="bottom"
              android:gravity="center"
                  android:layout_weight="0.05">

        <ImageView
            android:id="@+id/buy_now"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/button"/>

    </LinearLayout>

</LinearLayout>

这就是它的外观(忽略FAB和action按钮)

问题是当我从列表视图中删除元素时,按钮也会向上移动。我希望,无论ListView中有多少项,按钮始终位于底部

编辑

我试着用下面的方法使用相对布局-

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

    <com.android.fiby.TitleFont
        android:textColor="#5e240a"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textSize="40dp"
        android:text="בדיקה"
        android:id="@+id/list_title"
        android:layout_alignParentTop="true" 
        android:layout_centerHorizontal="true"/>



    <ListView
        android:layout_below="@+id/list_title"
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>

    <ImageView
        android:layout_below="@android:id/list"
        android:id="@+id/buy_now"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/button"
        android:layout_gravity="center"
        android:layout_alignParentBottom="true"/>


</RelativeLayout>

但问题是listview覆盖了按钮-


我不想更改列表的高度,因为禁用图像可见性的其他活动会使用该列表。

您应该尝试使用RelativeLayout并使用此行

android:layout_alignParentBottom="true"

这将在底部停靠项目

您可以使用RelativeLayout代替LinearLayout,并将此按钮设置为始终位于listview下方。大概是这样的:

<LinearLayout android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:visibility="visible"
          android:layout_gravity="bottom"
          android:gravity="center"
          android:id="@+id/listview"
          android:layout_weight="0.05">

    <ImageView
        android:id="@+id/buy_now"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/listview"
        android:src="@drawable/button"/>
编辑1: 尝试将ListView设置在按钮上方,而不是ListView下方的按钮

<ListView
    android:layout_below="@+id/list_title"
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@+id/buy_now"/>

<Button
    android:id="@+id/buy_now"
    android:layout_marginTop="5dp"
    android:layout_marginBottom="5dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_alignParentBottom="true"/>

或者您可以使用滚动视图

<ListView
    android:layout_below="@+id/list_title"
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@+id/buy_now"/>

<Button
    android:id="@+id/buy_now"
    android:layout_marginTop="5dp"
    android:layout_marginBottom="5dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_alignParentBottom="true"/>