带你实现ViewGroup规定行数、item居中的流式布局

在写该文章之前自己也写了一个用RecyclerView实现的流式布局RecyclerView实现的流式布局,也得到一些关注,但是也有不少的朋友提出了相关的问题,比如想规定行数的流式布局,还有item高度不统一时动态显示item的位置问题。于是近两天就简单写了个ViewGroup实现的流式布局:

这里在时给出了四种情况的用例:
(一)文字统一高度,也就是默认的情况

这里详见:NormalLoadActivity

(二)不同高度的文本,没设置居中显示的情况


这里详见:DiffHeightTextActivity

(三)不同高度的文本,设置居中显示的情况

这里详见:DiffHeightTextCenterActivity

(四)规定行数的流式布局

这里详见:LineFlowActivity

属性:

 <declare-styleable name="FlowLayout">
      
      <attr name="is_line_center" format="boolean" />
 declare-styleable>

<declare-styleable name="LineFlowLayout">
      
      <attr name="flow_line_count" format="integer" />
declare-styleable>

<declare-styleable name="ScrollFlowLayout">
      
      <attr name="effect_top_color" format="color" />
      
      <attr name="effect_bottom_color" format="color" />
      
      <attr name="need_effect" format="boolean" />
declare-styleable>

gradle依赖

allprojects {
        repositories {
                ...
                maven { url 'https://jitpack.io' }
        }
}

dependencies {
        compile 'com.github.1002326270xc:FlowView-master:v1.1'
}

后期添加(自带滑动结构的流式布局):

这里详见:ScrollFlowActivity

thanks:这里滑动的处理借鉴的SuitLines(一个图标控件)、SwipeDelMenuLayout(侧拉菜单)

关于我:

email: [email protected]
简书:enter
github:enter

你可能感兴趣的:(android)