Skip to content

Commit 1465baa

Browse files
committed
modify README.MD
1 parent 46bd0cb commit 1465baa

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,61 @@ dependencies{
3434
```
3535

3636
##Usage
37+
38+
###Extends BaseIndicaorBanner and Set Data Type
39+
40+
```Java
41+
public class SimpleImageBanner extends BaseIndicaorBanner<BannerItem, SimpleImageBanner> {
42+
private ColorDrawable colorDrawable;
43+
44+
public SimpleImageBanner(Context context) {
45+
this(context, null, 0);
46+
}
47+
48+
public SimpleImageBanner(Context context, AttributeSet attrs) {
49+
this(context, attrs, 0);
50+
}
51+
52+
public SimpleImageBanner(Context context, AttributeSet attrs, int defStyle) {
53+
super(context, attrs, defStyle);
54+
colorDrawable = new ColorDrawable(Color.parseColor("#555555"));
55+
}
56+
57+
@Override
58+
public void onTitleSlect(TextView tv, int position) {
59+
final BannerItem item = list.get(position);
60+
tv.setText(item.title);
61+
}
62+
63+
@Override
64+
public View onCreateItemView(int position) {
65+
View inflate = View.inflate(context, R.layout.adapter_simple_image, null);
66+
ImageView iv = ViewFindUtils.find(inflate, R.id.iv);
67+
68+
final BannerItem item = list.get(position);
69+
int itemWidth = dm.widthPixels;
70+
int itemHeight = (int) (itemWidth * 360 * 1.0f / 640);
71+
iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
72+
iv.setLayoutParams(new LinearLayout.LayoutParams(itemWidth, itemHeight));
73+
74+
String imgUrl = item.imgUrl;
75+
76+
if (!TextUtils.isEmpty(imgUrl)) {
77+
Glide.with(context)
78+
.load(imgUrl)
79+
.override(itemWidth, itemHeight)
80+
.centerCrop()
81+
.placeholder(colorDrawable)
82+
.into(iv);
83+
} else {
84+
iv.setImageDrawable(colorDrawable);
85+
}
86+
87+
return inflate;
88+
}
89+
}
90+
```
91+
3792
###The Most Complex
3893
in layout xml
3994

0 commit comments

Comments
 (0)