Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/guojunustb/VerticalBannerView

a vertical banner view in android.you can find it in 淘宝app、京东app...
https://github.com/guojunustb/VerticalBannerView

Last synced: 2 months ago
JSON representation

a vertical banner view in android.you can find it in 淘宝app、京东app...

Awesome Lists containing this project

README

        

### VerticalBannerView

`VerticalBannerView`是一个android平台下的自定义控件,通常用来展示广告,类似`淘宝头条`,它的样式如下:

![](art.gif)

### Feature

1. 可自由定义展示的内容
2. 使用方式类似ListView/RecyclerView
3. 可为当前的内容添加各种事件,比如点击打开某个页面等

### Attention

API >= 11

### Usage

可以类比`ListView`

0. 添加依赖

- Add it in your root build.gradle at the end of repositories:

```

allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
```
- Add the dependency

```
dependencies {
compile 'com.github.Rowandjj:VerticalBannerView:1.0'
}
```

1. 定义item的布局

```









```

2. 实现adapter

```
public class SampleAdapter01 extends BaseBannerAdapter {

private List mDatas;

public SampleAdapter01(List datas) {
super(datas);
}

@Override
public View getView(VerticalBannerView parent) {
return LayoutInflater.from(parent.getContext()).inflate(R.layout.item_01,null);
}

@Override
public void setItem(final View view, final Model01 data) {
TextView tv = (TextView) view.findViewById(R.id.tv_01);
tv.setText(data.title);
//你可以增加点击事件
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//比如打开url
Toast.makeText(view.getContext(),data.url,Toast.LENGTH_SHORT).show();
}
});
}
}
```

3. 在布局中增加view的声明

```
动画间隔900ms
app:gap="2000"/> ----->切换时长2000ms
```

4. 设置Adapter并启动

```
List datas02 = new ArrayList<>();
datas02.add(new Model01("Life was so beautiful","--->Life was so beautiful,"));
datas02.add(new Model01("From morning to evening","--->From morning to evening"));
datas02.add(new Model01("We enjoyed the road to school","--->We enjoyed the road to school,"));
datas02.add(new Model01("Birds chirped and Peace lingered","--->Birds chirped and Peace lingered"));
final SampleAdapter02 adapter02 = new SampleAdapter02(datas02);
final VerticalBannerView banner02 = (VerticalBannerView) findViewById(R.id.banner_02);
banner02.setAdapter(adapter02);
banner02.start();
```

5. 更新数据

```
List newData = new ArrayList<>();
newData.add(new Model01("锄禾日当午","--->锄禾日当午"));
newData.add(new Model01("汗滴禾下土","--->汗滴禾下土"));
newData.add(new Model01("谁知盘中餐","--->谁知盘中餐"));
newData.add(new Model01("粒粒皆辛苦","--->粒粒皆辛苦"));
adapter02.setData(newData);

```

6. 停止

```
banner02.stop();
```