gpt4 book ai didi

android - ListView 的高度

转载 作者:搜寻专家 更新时间:2023-11-01 08:43:08 25 4
gpt4 key购买 nike

我一直在尝试为我的应用制作布局,我在其中设置了 android:layout_height="wrap_content"

这是我的代码::

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.hp.money.DashBoard">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.CardView
android:id="@+id/cv_amount_display"
android:layout_width="match_parent"
android:layout_height="200dp">
.....
</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
card_view:cardCornerRadius="10dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/last_10_transaction" />

<ListView
android:id="@+id/last_transactions_lv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>

我在 ScrollView 中使用 ListView,这是个坏主意,我知道!我相信它会导致一些滚动问题。但是我必须在运行时动态更新屏幕上的数据,我认为只有 ListView 可以处理它。如果有任何其他View可以做到这一点,请提出建议。

现在,问题是即使 ListView 的数据源有 10 个项目,ListView 的高度始终保持等于一个 listView 元素的大小,但 listview 的高度设置为 wrap_content ,所以它可能应该相应地调整大小。但事实并非如此!如何解决这个问题?

这就是它的外观,即使 Listview 有 10 个项目!ListView 是标题为 LAST 10 TRANSACTIONS 的那个

The ListView is the one which has a heading as LAST 10 TRANSACTIONS

为什么我使用 ScrollView??

我放了一个 ScrollView ,因为 ListView 中的条目数量可能很多,所以我希望当用户滚动查看 ListView 中当前不可见的条目时,整个页面都会滚动,而不仅仅是 ListView 。

最佳答案

“在运行时动态地将数据插入 Listview”是什么意思?如果您正在动态修改列表数据,则 ListView 可以在内部处理它。在那种情况下你不需要做任何事情。因此,您可以删除 ScrollView,使其正常工作。

关于android - ListView 的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30935551/

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