gpt4 book ai didi

java - 如何让ListView调整大小?

转载 作者:行者123 更新时间:2023-12-01 18:27:49 25 4
gpt4 key购买 nike

图片1

enter image description here

图2

enter image description here

如何调整ListView的大小?

这个ListView没问题。OK ListView 1 图片

enter image description here

确定ListView 2图片

enter image description here

我已经尝试了所有的布局。这没有帮助。

我有一个 fragment 容器:

<?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 代码将更改 Fragments 容器的内部内容。两个 fragment 几乎完全相同。有什么问题吗?

最佳答案

    <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>

您可以通过多种方式做到这一点。在这里您可以将自己的 View 设置为页眉和页脚。

关于java - 如何让ListView调整大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60205038/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com