ListView占用LinearLayout中的所有空间

仲裁人

我有LinearLayout包含一个ListView和一个LinearLayout

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:orientation="vertical">

    <ListView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp">

        <EditText
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:hint="Hej"/>
    </LinearLayout>
</LinearLayout>

ListView占据整个布局和LinearLayoutEditText获取屏幕的底部边缘下方添加是不可见的。我怎样才能解决这个问题?我尝试过,layout_weight但是没有

克诺索斯

那是因为您正在使用fill_parent,它将完全做到这一点。

您可以尝试一些类似的方法...这将导致ListView扩展以填充空间。

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:orientation="vertical">

    <ListView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="0dp"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:hint="Hej"/>
    </LinearLayout>
</LinearLayout>

另一种选择是使用RelativeLayout。只要ListView的高度不是wrap_content,就应该可以。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    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"
    android:orientation="vertical">

    <ListView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_above="@+id/footer"
        android:layout_height="match_parent"/>

    <LinearLayout
        android:id="@+id/footer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:padding="10dp">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:hint="Hej"/>
    </LinearLayout>
</RelativeLayout>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

mergeChangesFromContextDidSaveNotification占用所有空间

ListView占用了所有屏幕空间

Docker占用了所有空间100%

Android XML布局-ImageView占用所有空间

如何使nohup不创建任何输出文件并因此不占用所有空间?

为什么此bash命令占用设备上的所有空间?

iOS - 占用水平 UIStackView 中的所有可用空间

如何自动占用CSS网格中的所有可用空间

如何获得带有空JLabel的JPanel来占用GridBagLayout中的空间

从数组javascript中删除所有空间

删除图像中的所有空白空间

如何使墨水效果填充BottomNavigationBarItem中的所有空间

聚合物应用程序抽屉在关闭时左悬着包装,内容没有占用所有空间

如何使按钮用完BorderLayout中的所有空间而没有空白?

创建一个div,该div占用其他两个之间的所有空间

Flutter ListView.Builder Card 小部件占用了屏幕的所有垂直空间

使输入占用所有剩余空间

Flutter GridView 占用所有屏幕空间?

使div扩展以占用所有可用空间

使TabBarView占用所有剩余空间

GridBagLayout中的组件放置在中心,而不会占用所有可用空间

使ImageView占用所有可用的垂直空间并增加宽度以在RelativeLayout中按比例放大/缩小

使Flexbox中的项目占用所有垂直和水平空间

如何使表格中的第二行占用所有单元格的空间?

CSS:使列表中的所有<li>宽度相同,并占用100%的可用空间

Xamarin-NavigationPage.TitleView中的StackLayout不会使用所有空间?

在XWiki中获取当前用户可以访问的所有空间

Linux来宾(在VirtualBox中)不会使用动态VDI磁盘的所有空间

列中的扩展listview占用了额外的空间