private ArrayList<TalkRecommendBean> talkRecommendBeans;
private ArrayList<TalkRecommendBean> talkHeaderRecommendBeans;
private RecyclerItemTypeClickListener onRecyclerItemClickListener;
private int screenWidth;
public WaterFallAdapter(Context context) {
this.context = context;
LayoutInflater = LayoutInflater.from(context);
talkRecommendBeans = new ArrayList<>();
talkHeaderRecommendBeans = new ArrayList<>();
screenWidth = ScreenUtils.getScreenWidth(context);
}
public void setData(ArrayList<TalkRecommendBean> datas) {
talkRecommendBeans = datas;
notifyDataSetChanged();
}
public void addData(ArrayList<TalkRecommendBean> datas) {
talkRecommendBeans.addAll(datas);
notifyDataSetChanged();
}
public ArrayList<TalkRecommendBean> getCurrentData() {
return talkRecommendBeans;
}
public void setOnRecyclerItemClickListener(RecyclerItemTypeClickListener onRecyclerItemClickListener) {
this.onRecyclerItemClickListener = onRecyclerItemClickListener;
}
@Override
public int getItemCount() {
// 加一是因为添加了头部
return talkRecommendBeans.size();
}
@Override
public IViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = null;
IViewHolder holder = null;
view = LayoutInflater.inflate(R.layout.app_talk_item_recylerview, parent, false);
holder = new SimpleViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(IViewHolder holder, int position) {
setListHolder(holder, position);
}
private void setListHolder(IViewHolder holder, int position) {
SimpleViewHolder simpleViewHolder = (SimpleViewHolder) holder;
RelativeLayout.LayoutParams lpImg = (RelativeLayout.LayoutParams) simpleViewHolder.info_bg_icon.getLayoutParams();
// LinearLayout.LayoutParams linearParams =(LinearLayout.LayoutParams) simpleViewHolder.user_avater.getLayoutParams(); //取控件textView当前的布局参数 linearParams.height = 20;// 控件的高强制设成20
if (position % 2 == 0) {
lpImg.width = screenWidth / 2;
lpImg.height = screenWidth * 2 / 3 - 100;
simpleViewHolder.info_bg_icon.setLayoutParams(lpImg);
} else {
lpImg.width = screenWidth / 2;
lpImg.height = screenWidth * 2 / 3;
simpleViewHolder.info_bg_icon.setLayoutParams(lpImg);
}
TalkRecommendBean talkRecommendBean = talkRecommendBeans.get(position - 1);
simpleViewHolder.recycler_view_title.setText(talkRecommendBean.title);
simpleViewHolder.recycler_view_zan.setText(talkRecommendBean.likeNums + "");
simpleViewHolder.user_avater_name.setText(talkRecommendBean.nickName);
if (talkRecommendBean.isTop == 0)
simpleViewHolder.is_top_view.setVisibility(View.GONE);
else
simpleViewHolder.is_top_view.setVisibility(View.VISIBLE);
if (talkRecommendBean.targetType == 23)
simpleViewHolder.info_id_video_icon.setVisibility(View.VISIBLE);
else
simpleViewHolder.info_id_video_icon.setVisibility(View.GONE);
// Glide.with(context)
// .load(talkRecommendBean.coverImgUrl)
// .asBitmap()//强制Glide返回一个Bitmap对象
// .into(new Tram);
ImageDisplayUtils.dispalyImg(context, talkRecommendBean.coverImgUrl, simpleViewHolder.info_bg_icon);
// if (!TextUtils.isEmpty(talkRecommendBean.coverImgUrl)){
// Picasso.with(context).load(talkRecommendBean.coverImgUrl).into(simpleViewHolder.info_bg_icon);
// }
if (TextUtils.isEmpty(talkRecommendBean.headImgUrl)) {
Picasso.with(context)
.load(R.drawable.icon_face2_0)
.placeholder(R.drawable.icon_face2_0)
.error(R.drawable.icon_face2_0)
.transform(new CircleTransform())
.into(simpleViewHolder.user_avater);
} else {
Picasso.with(context)
.load(talkRecommendBean.headImgUrl)
.placeholder(R.drawable.icon_face2_0)
.error(R.drawable.icon_face2_0)
.transform(new CircleTransform())
.into(simpleViewHolder.user_avater);
}
}
class SimpleViewHolder extends IViewHolder {
TextView recycler_view_title;
TextView recycler_view_zan;
TextView user_avater_name;
TextView is_top_view;
ImageView user_avater;
ImageView info_bg_icon;
ImageView info_id_video_icon;
LinearLayout cardview;
public SimpleViewHolder(View view) {
super(view);
recycler_view_title = (TextView) view.findViewById(R.id.recycler_view_title);
user_avater_name = (TextView) view.findViewById(R.id.user_avater_name);
is_top_view = (TextView) view.findViewById(R.id.is_top_view);
recycler_view_zan = (TextView) view.findViewById(R.id.recycler_view_zan);
user_avater = (ImageView) view.findViewById(R.id.user_avater);
info_bg_icon = (ImageView) view.findViewById(R.id.info_bg_icon);
info_id_video_icon = (ImageView) view.findViewById(R.id.info_id_video_icon);
cardview = (LinearLayout) view.findViewById(R.id.cardview);
RelativeLayout.LayoutParams lpImg = (RelativeLayout.LayoutParams) info_bg_icon.getLayoutParams();
lpImg.width = screenWidth / 2;
lpImg.height = screenWidth * 2 / 3;
info_bg_icon.setLayoutParams(lpImg);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (onRecyclerItemClickListener != null) {
onRecyclerItemClickListener.onItemClickListener(getLayoutPosition(), 1);
}
}
});
}
}
}
|
||
| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
|
||
| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
|
||
| 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 |
|
|
|
||
| 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 |
|
|
| 133 |
|
|
| 134 |
|
|
| 135 |
|
|
| 136 |
|
|
| 137 |
|
|
| 138 |
|
|
| 139 |
|
|
| 140 |
|
|
| 141 |
|
|
| 142 |
|
|
| 143 |
|
|
| 144 |
|
|
| 145 |
|
|
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
|
|
| 150 |
|
|
|
||
| 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 |
|
|
| 133 |
|
|
| 134 |
|
|
| 135 |
|
|
| 136 |
|
|
| 137 |
|
|
| 138 |
|
|
| 139 |
|
|
| 140 |
|
|
| 141 |
|
|
| 142 |
|
|
| 143 |
|
|
| 144 |
|
|
| 145 |
|
|
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
|
|
| 150 |
|
|
| 151 |
|
|
| 152 |
|
|
| 153 |
|
|
| 154 |
|
|
| 155 |
|
|
| 156 |
|
|
| 157 |
|
|
| 158 |
|
|
| 159 |
|
|
| 160 |
|
|
| 161 |
|
|
| 162 |
|
|
| 163 |
|
|
| 164 |
|
|
| 165 |
|
|
| 166 |
|
|
| 167 |
|
|
| 168 |
|
|
| 169 |
|
|
| 170 |
|
|
| 171 |
|
|
| 172 |
|
|
| 173 |
|
|
| 174 |
|
|
| 175 |
|
|
| 176 |
|
|
| 177 |
|
|
| 178 |
|
|
| 179 |
|
|
| 180 |
|
|
| 181 |
|
|
| 182 |
|
|
| 183 |
|
|
| 184 |
|
|
| 185 |
|
|
| 186 |
|
|
| 187 |
|
|