package com.gh.common.util; import android.content.Context; import android.content.Intent; import android.widget.LinearLayout; import com.facebook.drawee.drawable.ScalingUtils; import com.facebook.drawee.view.SimpleDraweeView; import com.gh.gamecenter.ImageViewerActivity; import java.util.ArrayList; import java.util.List; /** * Created by khy on 2016/11/8. *

* 初始化资讯关注-内容图片 **/ public class ConcernContentUtils { public static void addContentPic(Context context, LinearLayout linearLayout, List list, String entrance, int width) { int count = list.size(); int index = 0; for (int i = 0, size = (int) Math.ceil(list.size() / 3.0f); i < size; i++) { int type = count % 3; LinearLayout ll; switch (type) { case 0: ll = new LinearLayout(context); ll.setOrientation(LinearLayout.HORIZONTAL); for (int j = 0; j < 3; j++) { ll.addView(getImageView(context, list, entrance, index, width, 0)); index += 1; } linearLayout.addView(ll); count -= 3; break; case 1: linearLayout.addView(getImageView(context, list, entrance, index, width, 1)); count -= 1; index += 1; break; case 2: ll = new LinearLayout(context); ll.setOrientation(LinearLayout.HORIZONTAL); for (int j = 0; j < 2; j++) { ll.addView(getImageView(context, list, entrance, index, width, 2)); index += 1; } linearLayout.addView(ll); count -= 2; break; } } } private static SimpleDraweeView getImageView(final Context context, final List list, final String entrance, final int position, int width, int type) { SimpleDraweeView imageView; LinearLayout.LayoutParams lparams; switch (type) { case 0: imageView = new SimpleDraweeView(context); lparams = new LinearLayout.LayoutParams( 0, width / 3 - DisplayUtils.dip2px(context, 4)); lparams.setMargins(DisplayUtils.dip2px(context, 2), 0, DisplayUtils.dip2px(context, 2), DisplayUtils.dip2px(context, 4)); lparams.weight = 1; imageView.setLayoutParams(lparams); ImageUtils.display(context.getResources(), imageView, width / 3 - DisplayUtils.dip2px(context, 4), ScalingUtils.ScaleType.CENTER_CROP, list.get(position)); break; case 1: imageView = new SimpleDraweeView(context); lparams = new LinearLayout.LayoutParams(width, width / 2); lparams.setMargins(DisplayUtils.dip2px(context, 2), 0, DisplayUtils.dip2px(context, 2), DisplayUtils.dip2px(context, 4)); imageView.setLayoutParams(lparams); ImageUtils.display(context.getResources(), imageView, lparams.width, ScalingUtils.ScaleType.CENTER_CROP, list.get(position)); break; default: imageView = new SimpleDraweeView(context); lparams = new LinearLayout.LayoutParams( 0, width / 2 - DisplayUtils.dip2px(context, 4)); lparams.setMargins(DisplayUtils.dip2px(context, 2), 0, DisplayUtils.dip2px(context, 2), DisplayUtils.dip2px(context, 4)); lparams.weight = 1; imageView.setLayoutParams(lparams); ImageUtils.display(context.getResources(), imageView, width / 2 - DisplayUtils.dip2px(context, 4), ScalingUtils.ScaleType.CENTER_CROP, list.get(position)); break; } imageView.setOnClickListener(v -> { Intent checkIntent = ImageViewerActivity.getIntent(context, (ArrayList) list, position, entrance); context.startActivity(checkIntent); }); return imageView; } }