为什么列表视图项长度由第一项设置

时间:2017-09-12 08:39:25

标签: android listview

我创建了水平滚动列表视图。我可以毫无问题地从db填充。问题是;项目的整个长度设置为第一个项目的长度。

Like this

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
  <HorizontalScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
            <ListView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
   </HorizontalScrollView>
</RelativeLayout>

2 个答案:

答案 0 :(得分:3)

此问题的简单解决方案是使用 Recyclerview 而不是列表视图。 将Horizo​​ntalScrollview添加到LinearLayout将不起作用。 我已经尝试了很多解决方案here 经过大量的搜索,我到现在为止,我的解决方案是Recyclerview。 从here我学到了,如何使用它。

答案 1 :(得分:0)

您需要使listView高度与父

匹配
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
   <HorizontalScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
   </HorizontalScrollView>
</RelativeLayout>
相关问题