大于两个的if分支,使用switch
This commit is contained in:
@ -25,28 +25,33 @@ public class ConcernContentUtils {
|
||||
int index = 0;
|
||||
for (int i = 0, size = (int) Math.ceil(list.size() / 3.0f); i < size; i++) {
|
||||
int type = count % 3;
|
||||
if (type == 0) {
|
||||
LinearLayout ll = new LinearLayout(context);
|
||||
ll.setOrientation(LinearLayout.HORIZONTAL);
|
||||
for (int j = 0; j < 3; j++) {
|
||||
ll.addView(getImageView(context, list, entrance, index, width, 0));
|
||||
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;
|
||||
}
|
||||
linearLayout.addView(ll);
|
||||
count -= 3;
|
||||
} else if (type == 1) {
|
||||
linearLayout.addView(getImageView(context, list, entrance, index, width, 1));
|
||||
count -= 1;
|
||||
index += 1;
|
||||
} else if (type == 2) {
|
||||
LinearLayout 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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -54,34 +59,39 @@ public class ConcernContentUtils {
|
||||
private static SimpleDraweeView getImageView(final Context context, final List<String> list, final String entrance,
|
||||
final int position, int width, int type) {
|
||||
SimpleDraweeView imageView;
|
||||
if (type == 0) {
|
||||
imageView = new SimpleDraweeView(context);
|
||||
LinearLayout.LayoutParams 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.getInstance().display(context.getResources(), imageView,
|
||||
ScalingUtils.ScaleType.CENTER_CROP, list.get(position));
|
||||
} else if (type == 1) {
|
||||
imageView = new SimpleDraweeView(context);
|
||||
LinearLayout.LayoutParams 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.getInstance().display(context.getResources(), imageView,
|
||||
ScalingUtils.ScaleType.CENTER_CROP, list.get(position));
|
||||
} else {
|
||||
imageView = new SimpleDraweeView(context);
|
||||
LinearLayout.LayoutParams 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.getInstance().display(context.getResources(), imageView,
|
||||
ScalingUtils.ScaleType.CENTER_CROP, list.get(position));
|
||||
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.getInstance().display(context.getResources(), imageView,
|
||||
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.getInstance().display(context.getResources(), imageView,
|
||||
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.getInstance().display(context.getResources(), imageView,
|
||||
ScalingUtils.ScaleType.CENTER_CROP, list.get(position));
|
||||
break;
|
||||
}
|
||||
imageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user