【Android开源库】AndroidStaggeredGrid:是一个支持实现多行多列且可变尺寸的阶梯形网格视图的开源库

AndroidStaggeredGrid是etsy实现的一个android瀑布流控件,没有继承ListView和Gridview,而是从更深层的AbsListVew着手实现。

特性

 

  • 设置列数,可以分别为横屏和竖屏指定不同的值
  • 屏幕方向改变时保持项的添加顺序不改变
  • 设置列表项之间的间隔
  • 支持添加header和footer
  • 支持OnScrollListener接口

使用例子

1. 将 StaggeredGridView 加入到需要显示的布局文件中,如:

1 <com.etsy.android.grid.StaggeredGridView
2        xmlns:android="http://schemas.android.com/apk/res/android"
3        xmlns:app="http://schemas.android.com/apk/res-auto"
4        android:id="@+id/grid_view"
5        android:layout_width="match_parent"
6        android:layout_height="match_parent"
7        app:item_margin="8dp"
8        app:column_count="@integer/column_count" />

2. 配置属性:

1 item_margin - The margin around each grid item (default 0dp).
2 column_count - The number of columns displayed. Will override column_count_portrait and column_count_landscape if present (default 0)
3 column_count_portrait - The number of columns displayed when the grid is in portrait (default 2).
4 column_count_landscape - The number of columns displayed when the grid is in landscape (default 3).
5 grid_paddingLeft - Padding to the left of the grid. Does not apply to headers and footers (default 0).
6 grid_paddingRight - Padding to the right of the grid. Does not apply to headers and footers (default 0).
7 grid_paddingTop - Padding to the top of the grid. Does not apply to headers and footers (default 0).
8 grid_paddingBottom - Padding to the bottom of the grid. Does not apply to headers and footers (default 0).

3. 配置适配器,这与使用GridView/ListView时基本一样:

1 ListAdapter adapter = ...;
2  
3 StaggeredGridView gridView = (StaggeredGridView) findViewById(R.id.grid_view);
4  
5 gridView.setAdapter(adapter);

github网址https://github.com/etsy/AndroidStaggeredGrid 文档https://github.com/etsy/AndroidStaggeredGrid

 

【原文地址】伯乐在线:http://hao.jobbole.com/androidstaggeredgrid/

posted @ 2014-07-04 09:09  风景线外  阅读(1113)  评论(0编辑  收藏  举报