梯形网格视图开源库分析 AndroidStaggeredGrid

码农软件 · 软件分类 · Android UI 组件 · 2019-04-27 06:26:28

软件介绍

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

StaggeredGridView 的开发是因为该开源作者在实现其Etsy app时发现Google的Android库中没有提供相关功能以实现其需求,即需要在landscape & portrait两种模式下显示不同的行、列,且能在模、竖屏都保持单元格显示同步, 运行稳定,还要支持自定义页头 & 页脚。

该库使用简单,可以通过作者提供的/sample app的源码了解使用细节,如图:

AndroidStaggeredGrid-1 AndroidStaggeredGrid-2

AndroidStaggeredGrid-weixin

总的来说使用该库只需3步:

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

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<com.etsy.android.grid.StaggeredGridView
        android:id="@+id/grid_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:item_margin="8dp"
        app:column_count_portrait="2"
        app:column_count_landscape="3" />
 </FrameLayout>

2. 配置属性:

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

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

ListAdapter adapter = ...;
StaggeredGridView gridView = (StaggeredGridView) findViewById(R.id.grid_view);
gridView.setAdapter(adapter);

说明: 由于列宽在屏幕方向横竖变化时亦会变化, 网格视图需要每个单元格维护自身的宽高比例,该库提供了 DynamicHeightImageView 类作为示例实现单元格视图高度按其宽度变化的功能。

本文地址:https://codercto.com/soft/d/4470.html

21天学通C语言

21天学通C语言

(美国)琼斯(Bradley L.Jones) (美国)埃特肯(Peter Aitken) / 信达工作室 / 人民邮电出版社 / 2012-8 / 69.00元

《21天学通C语言(第6版•修订版)》是初学者学习C语言的经典教程。本版按最新的标准(ISO∕IEC:9899-1999),以循序渐进的方式介绍了C语言编程方面知识,并提供了丰富的实例和大量的练习。通过学习实例,并将所学的知识用于完成练习,读者将逐步了解、熟悉并精通C语言。《21天学通C语言(第6版•修订版)》包括四周的课程。第一周的课程介绍了C语言程序的基本元素,包括变量、常量、语句、表达式、函......一起来看看 《21天学通C语言》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

在线进制转换器
在线进制转换器

各进制数互转换器

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具