Android UI水平滑动的ListView(Horizontal ListView)

关于这个布局,网上资料很多,比如:

StackOverflow:Horizontal ListView in Android?
[url=http://stackoverflow.com/questions/3240331/horizontal-listview-in-android]http://stackoverflow.com/questions/3240331/horizontal-listview-in-android[/url]、

Github上搜索:Horizontal ListView
[url=https://github.com/MeetMe/Android-HorizontalListView]https://github.com/MeetMe/Android-HorizontalListView[/url]
[url=https://github.com/jess-anders/two-way-gridview]https://github.com/jess-anders/two-way-gridview[/url]
[url=https://github.com/lucasr/twoway-view]https://github.com/lucasr/twoway-view[/url]

百度一下:
Android UI开发: 横向ListView(HorizontalListView)及一个简单相册的完整实现
[url=http://blog.csdn.net/yanzi1225627/article/details/21294553]http://blog.csdn.net/yanzi1225627/article/details/21294553[/url]

大多数使用HorizontalScrollView(LinearLayout、GridView)布局,根据item数各种计算,都比较复杂。Android 5.0引入RecyclerView(被认为是下一代的ListView),使用它来实现更灵活,比较有名的TwoWayView也正在用RecyclerView重写。

这里使用RecyclerView简单实现一个能够横向水平滑动的ListView。

(1)需要导入android-support-v7-recyclerview.jar

(2)res/layout/recyclerview.xml
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"/>


(3)Fragment的实现
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View result = inflater.inflate(R.layout.recyclerview, container, false);
recyclerView = (RecyclerView) result.findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);

int spanCount = 1; // 只显示一行
layoutManager = new StaggeredGridLayoutManager(spanCount, StaggeredGridLayoutManager.HORIZONTAL);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);

return result;
}


最终效果图:
[img]http://dl2.iteye.com/upload/attachment/0107/5091/e7dc4b03-7016-39fe-a7ef-7d01429be107.gif[/img]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值