SingleImageViewRecyclerViewAdapter.java
4.03 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package com.cnlive.goldenline.ui.adapter;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.bumptech.glide.Glide;
import com.cnlive.goldenline.R;
import com.cnlive.goldenline.ui.base.BaseRecyclerAdapter;
import com.cnlive.goldenline.ui.widget.coverflow.ViewUtil;
import com.cnlive.goldenline.util.StringUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
/**
* Description:单ImageView RecyclerView 适配器
* Created on 2017/3/6
* Author : 萧
*/
public class SingleImageViewRecyclerViewAdapter extends BaseRecyclerAdapter<String> {
private int designWidth, designHeight;
private int leftmargin, rightMargin, topMargin, bottomMargin;
public SingleImageViewRecyclerViewAdapter(Context context) {
super(context);
}
public SingleImageViewRecyclerViewAdapter(Context context, int designWidth, int designHeight) {
super(context);
this.designWidth = designWidth;
this.designHeight = designHeight;
}
public int getDesignWidth() {
return designWidth;
}
public void setDesignWidth(int designWidth) {
this.designWidth = designWidth;
}
public int getDesignHeight() {
return designHeight;
}
public void setDesignHeight(int designHeight) {
this.designHeight = designHeight;
}
public int getLeftmargin() {
return leftmargin;
}
public void setLeftmargin(int leftmargin) {
this.leftmargin = leftmargin;
}
public int getRightMargin() {
return rightMargin;
}
public void setRightMargin(int rightMargin) {
this.rightMargin = rightMargin;
}
public int getTopMargin() {
return topMargin;
}
public void setTopMargin(int topMargin) {
this.topMargin = topMargin;
}
public int getBottomMargin() {
return bottomMargin;
}
public void setBottomMargin(int bottomMargin) {
this.bottomMargin = bottomMargin;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.layout_single_img, parent, false);
return new SingleImageViewHolder(view);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof SingleImageViewHolder) {
SingleImageViewHolder viewHolder = (SingleImageViewHolder) holder;
viewHolder.show(mContext, mItems.get(position));
}
}
class SingleImageViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.single_img)
ImageView img;
public SingleImageViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
public void show(Context mContext, String s) {
if (mContext != null && !StringUtils.isEmpty(s)) {
if (designHeight > 0 && designWidth > 0) {
ViewGroup.LayoutParams params = img.getLayoutParams();
params.width = ViewUtil.Dp2Px(mContext, designWidth);
params.height = ViewUtil.Dp2Px(mContext, designHeight);
img.setLayoutParams(params);
}
if (leftmargin > 0 || rightMargin > 0 || topMargin > 0 || bottomMargin > 0) {
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) img.getLayoutParams();
params.leftMargin = ViewUtil.Dp2Px(mContext, leftmargin);
params.rightMargin = ViewUtil.Dp2Px(mContext, rightMargin);
params.topMargin = ViewUtil.Dp2Px(mContext, topMargin);
params.bottomMargin = ViewUtil.Dp2Px(mContext, bottomMargin);
img.setLayoutParams(params);
}
Glide.with(mContext).load(s).override(designWidth, designHeight).into(img);
}
}
}
}