gpt4 book ai didi

Android ListView 切断比第一个项目更宽的项目

转载 作者:行者123 更新时间:2023-11-30 00:43:30 24 4
gpt4 key购买 nike

我在 Horizo​​ntalScrollView 中有一个 Listview。 ListView 保存文件路径,水平 ScrollView 旨在消除包装较长路径的需要。

除了 ListView 中任何比第一项长的项目都被切割成第一项的长度(无论第一项的宽度如何,其他项目都不会滚动),一切都完全按照预期工作超过那个宽度)。

这是给我带来麻烦的布局部分:

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layoutListView"
android:orientation="vertical"
android:layout_below="@+id/spFileTypes">

<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">

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

</HorizontalScrollView>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text=""
android:id="@+id/tvStatus"/>

</LinearLayout>

这是问题的截图:

listview issue screenshot

图像一直向右滚动。第三项是切断“.php”。我已经用长文件名和短文件名、许多列表(高位两位数)和只有少数的列表进行了尝试,在每种情况下,宽度限制似乎都取决于第一项的宽度。

每当列表发生变化时,它总是将其宽度限制为第一个元素的宽度。

期望的行为是让它与最宽项目的宽度相匹配。

我用谷歌搜索了我的心,翻阅了官方文档,但我被难住了。非常感谢任何帮助:)

最佳答案

不要将 ListView 包装在 Horizo​​ntalScrollView 中,试试这个:

<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal"/>

关于Android ListView 切断比第一个项目更宽的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42192362/

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