【发布时间】:2020-02-13 09:57:20
【问题描述】:
图片1
图2
如何使 ListView 可调整大小?
这个ListView没问题。 OK ListView 1 图片
OK 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>
OK 布局是搜索布局:
<?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 容器的内部内容。 两个片段几乎相同。 有什么问题?
【问题讨论】:
-
layout_weight="1" // 是问题所在。
-
只制作页眉 - 框架布局 - 线性布局内的页脚,看看区别
-
@Radhey 删除 weight = 1 没有帮助。