-
Notifications
You must be signed in to change notification settings - Fork 353
/
Copy pathCustomViewsActivity.java
54 lines (46 loc) · 1.79 KB
/
CustomViewsActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.stx.xhb.demo;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.blankj.utilcode.util.ToastUtils;
import com.stx.xhb.xbanner.XBanner;
import com.stx.xhb.demo.entity.CustomViewsInfo;
import java.util.ArrayList;
import java.util.List;
/**
* 自定义布局
*/
public class CustomViewsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_views);
initView();
}
private void initView() {
XBanner banner = (XBanner) findViewById(R.id.banner);
List<CustomViewsInfo> data = new ArrayList<>();
data.add(new CustomViewsInfo("#FFA54F"));
data.add(new CustomViewsInfo("#8EE5EE"));
data.add(new CustomViewsInfo("#00FA9A"));
data.add(new CustomViewsInfo("#CD8162"));
banner.setBannerData(R.layout.layout_custom_view, data);
banner.loadImage(new XBanner.XBannerAdapter() {
@Override
public void loadBanner(XBanner banner, Object model, View view, int position) {
TextView tvContent = (TextView) view.findViewById(R.id.tv);
tvContent.setText(String.valueOf(position + 1));
view.setBackgroundColor(Color.parseColor(((CustomViewsInfo) model).getXBannerUrl()));
}
});
banner.setOnItemClickListener(new XBanner.OnItemClickListener() {
@Override
public void onItemClick(XBanner banner, Object model, View view, int position) {
ToastUtils.showShort("点击了" + position);
}
});
}
}