一、横向滑动的ListView
首先是一篇关于能够横向滑动的ListView的实现,作者是大牛农民伯伯,地址http://www.cnblogs.com/over140/archive/2011/12/07/2275207.html,这篇文章介绍了一种能够在ListView非常宽,而屏幕显示不下的情况下能够左右滑动的解决方案。这种方案比较复杂自定义支持横向滚动的ListView。
我们有更好的方案,不用自定义组件,只要在布局文件里将ListView放在HorizontalScrollView即可,不用使用自定义组件。代码如下:
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!--head title-->
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableRow style="@style/biaotou" >
<TextView
style="@style/ListView_TextView_200dp"
android:text="@string/weihucishu" />
<View style="@style/list_item_cell_seperator_layout" />
<TextView
style="@style/ListView_TextView_200dp"
android:text="@string/baoyangriqi" />
<View style="@style/list_item_cell_seperator_layout" />
<TextView
style="@style/ListView_TextView_300dp"
android:text="@string/weixiuchejian" />
<View style="@style/list_item_cell_seperator_layout" />
</TableRow>
</TableLayout>
<ListView
android:id="@+id/listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000" />
</LinearLayout>
</HorizontalScrollView>
效果图如下:(竟然不支持gif图片!!!!)
示例图片下载地址
二、横向增加Item的ListView
第一种情况是按照ListView原本的属性每次增加条目都是在下方,而有时候我们需要的是一种可以横向增加条目的ListView。
在此我们需要感谢大神的巨作,HorizontalListView
组件下载地址:https://github.com/dinocore1/DevsmartLib-Android
组件介绍地址:http://www.dev-smart.com/archives/34