HorizontalScrollView 嵌套listview实现列表左右、上下滑动、控件复用等功能

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qiantanlong/article/details/78631671

需求:就是要展示一组列表数据,上下滑动是必须的一般是ListView,但是由于横向内容也很多,需要左右滑动。大家都知道,单独横向或单独垂直滑动都没问题,但是一旦两者结合,必然会出现滑动冲突。大家也知道,ScrollView、ListView等列表控件嵌套使用,会出现显示不全等控件高度测量问题。最后就是大家都知道这个问题很难搞,需要解决奇葩的冲突。基于以上的问题的考虑,我开发这个功能也是费尽心思,呕心沥血,但是最后居然感觉被坑了,被坑了,被坑了……重要的事说三遍。因为其实很简单,不需要自定义控件,不需要解决冲突,原生控件,HorizontalScrollView 嵌套Listview解决问题。


<HorizontalScrollView
                android:scrollbars="none"
                android:id="@+id/my_horizontal_scrollview"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                    <ListView
                        android:id="@+id/lv_suspects"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:dividerHeight="1dp" />
                </LinearLayout>

            </HorizontalScrollView>

就这样就可以了,这是以行为显示条目,单行可以获取单击和长按的事件。

不是表格结构

猜你喜欢

转载自blog.csdn.net/qiantanlong/article/details/78631671