如何使listview可调整大小?

7jmck4yq  于 2021-07-12  发布在  Java
关注(0)|答案(1)|浏览(441)

图1

图2

如何调整listview的大小?
此列表视图正常。确定listview 1图片

确定listview 2图片

我试过所有的布局。那没用。
我有一个碎片容器:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/yellow"
    tools:context=".MainActivity">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/fragmentsContainer"/>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        app:menu="@menu/menu"
        android:id="@+id/bottomNavigation"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

确定布局是搜索布局:

<?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="match_parent"
    android:background="@color/yellow"
    android:id="@+id/searchAndListViewContainer"
    android:orientation="vertical">

    <SearchView
        android:id="@+id/searchView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorOfSearchView" />

    <ListView
        android:id="@+id/downloadedMusicListView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

不可编辑的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/darkGreen">

    <ListView
        android:id="@+id/musicListView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>

</LinearLayout>

如您所见,java代码将更改容器的内部内容。两个碎片几乎完全相同。有什么问题吗?

dbf7pr2w

dbf7pr2w1#

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

        <ListView
            android:id="@+id/lv"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/tv_footer"
            android:layout_below="@+id/tv_header" />

        <TextView
            android:id="@+id/tv_footer"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:background="#ff0000"
            android:gravity="center"
            android:text="Footer" />

        <TextView
            android:id="@+id/tv_header"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:background="#00ff00"
            android:gravity="center"
            android:orientation="vertical"
            android:text="Header" />        

   </RelativeLayout>

你可以用多种方法。在这里,您可以将自己的视图设置为页眉和页脚。

相关问题