关于这个布局,网上资料很多,比如:
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
(3)Fragment的实现
最终效果图:
[img]http://dl2.iteye.com/upload/attachment/0107/5091/e7dc4b03-7016-39fe-a7ef-7d01429be107.gif[/img]
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]