Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/paulyung541/LaybelLayout
自动换行布局 标签布局
https://github.com/paulyung541/LaybelLayout
Last synced: 3 months ago
JSON representation
自动换行布局 标签布局
- Host: GitHub
- URL: https://github.com/paulyung541/LaybelLayout
- Owner: paulyung541
- License: apache-2.0
- Created: 2016-11-07T08:33:52.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-05T01:34:06.000Z (over 7 years ago)
- Last Synced: 2024-06-16T05:40:30.004Z (5 months ago)
- Language: Java
- Homepage:
- Size: 262 KB
- Stars: 52
- Watchers: 5
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-github-android-ui - LaybelLayout - 标签布局 (TagView)
README
# LaybelLayout
这是一个可以根据内容自动换行的标签布局原理剖析请看http://www.jianshu.com/p/82f0053b8726
![image](https://github.com/paulyung541/LaybelLayout/blob/master/pic/demo1.jpg)
![image](https://github.com/paulyung541/LaybelLayout/blob/master/pic/demo2.jpg)
![image](https://github.com/paulyung541/LaybelLayout/blob/master/pic/demo3.jpg)##添加依赖
在Projectd的gradle文件里添加如下:
```groovy
maven { url 'https://jitpack.io' }
```
在项目主Module里添加如下:
```groovy
compile 'com.github.paulyung541:LaybelLayout:v1.2.0'
```自定义属性:
```xml
app:line_padding="Integer"
app:text_background="reference"
```## 示例
在xml里面添加该控件
```xml```
设置Adapter提供数据
**Note:** 这个Adapter可不是ListView的Adapter哦,是自己定义的,不过用法差不多
```java
laybelLayout = (LaybelLayout) findViewById(R.id.laybel_layout);
laybelLayout.setAdapter(new LaybelLayout.Adapter(Content.content));
```如果要使用其它子View,比如ImageView,则需要重写`Adapter.getView()`方法
```java
laybelLayout = (LaybelLayout) findViewById(R.id.laybelLayout);
laybelLayout.setAdapter(new LaybelLayout.Adapter(Content.images) {
@Override
public View getView() {
ImageView imageView = new ImageView(ImageActivity.this);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
ViewGroup.MarginLayoutParams params = new ViewGroup.MarginLayoutParams(getWidth() / 3, getWidth() / 3);
imageView.setLayoutParams(params);
return imageView;
}@Override
public void onDataSet(View v, String data) {
Glide.with(ImageActivity.this).load(data).into((ImageView) v);
}
});
```
添加点击事件
```java
laybelLayout.setOnItemClickListener(new LaybelLayout.OnItemClickListener() {
@Override
public void onItemClick(int p) {
Toast.makeText(DefaultTextViewActivity.this, Content.content[p], Toast.LENGTH_SHORT).show();
}
});
```