Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/paulyung541/LaybelLayout

自动换行布局 标签布局
https://github.com/paulyung541/LaybelLayout

Last synced: 3 months ago
JSON representation

自动换行布局 标签布局

Awesome Lists containing this project

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();
}
});
```