{"id":20254563,"url":"https://github.com/lrh1993/autoflowlayout","last_synced_at":"2025-04-05T11:12:31.464Z","repository":{"id":201374895,"uuid":"98521260","full_name":"LRH1993/AutoFlowLayout","owner":"LRH1993","description":"自定义ViewGroup,实现多功能流式布局与网格布局","archived":false,"fork":false,"pushed_at":"2017-08-08T01:24:54.000Z","size":352,"stargazers_count":668,"open_issues_count":23,"forks_count":108,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-29T10:11:16.778Z","etag":null,"topics":["autolayout","flowlayout","gridlayout"],"latest_commit_sha":null,"homepage":"http://lruheng.com/2017/08/05/AutoFlowLayout-%E5%A4%9A%E5%8A%9F%E8%83%BD%E6%B5%81%E5%BC%8F%E5%B8%83%E5%B1%80%E4%B8%8E%E7%BD%91%E6%A0%BC%E5%B8%83%E5%B1%80%E6%8E%A7%E4%BB%B6/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LRH1993.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-07-27T09:58:11.000Z","updated_at":"2025-03-27T23:03:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"c737b361-19c4-4bab-a6ae-4a093a2377b5","html_url":"https://github.com/LRH1993/AutoFlowLayout","commit_stats":null,"previous_names":["lrh1993/autoflowlayout"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LRH1993%2FAutoFlowLayout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LRH1993%2FAutoFlowLayout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LRH1993%2FAutoFlowLayout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LRH1993%2FAutoFlowLayout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LRH1993","download_url":"https://codeload.github.com/LRH1993/AutoFlowLayout/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247325694,"owners_count":20920714,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autolayout","flowlayout","gridlayout"],"created_at":"2024-11-14T10:33:41.390Z","updated_at":"2025-04-05T11:12:31.417Z","avatar_url":"https://github.com/LRH1993.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AutoFlowLayout\n### 一、AutoFlowLayout应用场景\n流式布局，在很多标签类的场景中可以用的；而网格布局在分类中以及自拍九宫格等场景很常见。如下所示：\n![](http://upload-images.jianshu.io/upload_images/3985563-8c7c5401f2602718.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\n如此使用频繁而又实现简单的控件，怎能不自己撸一个呢？控件，还是定制的好啊。\n### 二、AutoFlowLayout实现效果\n先介绍下自己撸的这个控件的功能及效果。\n#### 1.功能\n**流式布局**\n-  自动换行\n- 行数自定：单行/多行\n- 支持单选/多选\n- 支持行居中/靠左显示\n- 支持添加/删除子View\n- 支持子View点击/长按事件\n\n**网格布局**\n-  行数/列数自定\n-  支持单选/多选\n- 支持添加/删除子View\n- 支持子View点击/长按事件\n- 支持添加多样式分割线及横竖间隔\n#### 2.效果\n下面以gif图的形式展现下实现的效果，样式简单了些，不过依然能展示出这个简单控件的多功能实用性。  \n\n**流式布局** \n\n![](http://upload-images.jianshu.io/upload_images/3985563-a0d0d19ddb77a9df.gif?imageMogr2/auto-orient/strip)\n     \n![](http://upload-images.jianshu.io/upload_images/3985563-e3ae7ae58423c373.gif?imageMogr2/auto-orient/strip)  \n\n**网格布局** \n\n![](http://upload-images.jianshu.io/upload_images/3985563-3723ba8a6b0c1114.gif?imageMogr2/auto-orient/strip)  \n\n最后一个是带间隔以及分割线的，由于录屏原因，只在跳过去的一瞬间显示了粉红色的一条线。真实如下图所示，可以定义横竖间距的大小，以及分割线的颜色，宽度。  \n![](http://upload-images.jianshu.io/upload_images/3985563-ba1e847f4c039f3c.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\n### 三、AutoFlowLayout使用\n#### 1.添加依赖\n①.在项目的 build.gradle 文件中添加\n```\nallprojects {\n\t\trepositories {\n\t\t\t...\n\t\t\tmaven { url 'https://jitpack.io' }\n\t\t}\n\t}\n```\n②.在 module 的 build.gradle 文件中添加依赖\n```\ndependencies {\n\t        compile 'com.github.LRH1993:AutoFlowLayout:1.0.5'\n\t}\n```\n#### 2.属性说明\n下表是自定义的属性说明，可在xml中声明，同时有对应的get/set方法，可在代码中动态添加。\n![](http://upload-images.jianshu.io/upload_images/3985563-9cc258fb8363af39.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\n#### 3.使用示例\n**布局**\n```\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n    \u003cRelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n                    android:layout_width=\"match_parent\"\n                    android:layout_height=\"match_parent\"\u003e\n    \u003ccom.example.library.AutoFlowLayout\n        android:id=\"@+id/afl_cotent\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"/\u003e\n\u003c/RelativeLayout\u003e\n```\n**代码设置数据**\n```\nmFlowLayout.setAdapter(new FlowAdapter(Arrays.asList(mData)) {\n            @Override\n            public View getView(int position) {\n                View item = mLayoutInflater.inflate(R.layout.special_item, null);\n                TextView tvAttrTag = (TextView) item.findViewById(R.id.tv_attr_tag);\n                tvAttrTag.setText(mData[position]);\n                return item;\n            }\n        });\n```\n与ListView,GridView使用方式一样，实现FlowAdapter即可。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flrh1993%2Fautoflowlayout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flrh1993%2Fautoflowlayout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flrh1993%2Fautoflowlayout/lists"}