消息评论功能 基本完成
This commit is contained in:
@ -0,0 +1,98 @@
|
||||
package com.gh.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.facebook.drawee.drawable.ScalingUtils;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.gh.gamecenter.ViewImageActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/8.
|
||||
*
|
||||
* 初始化z资讯关注-内容图片
|
||||
*
|
||||
**/
|
||||
public class ConcernContentUtils {
|
||||
|
||||
public static void addContentPic(int width, LinearLayout linearLayout, List<String> list, Context context) {
|
||||
int count = list.size();
|
||||
LinearLayout ll;
|
||||
int index = 0;
|
||||
for (int i = 0, size = (int) Math.ceil(list.size() / 3.0f); i < size; i++) {
|
||||
switch (count % 3) {
|
||||
case 0:
|
||||
ll = new LinearLayout(context);
|
||||
ll.setOrientation(LinearLayout.HORIZONTAL);
|
||||
for (int j = 0; j < 3; j++) {
|
||||
ll.addView(getImageView(list, index, width, 0, context));
|
||||
index += 1;
|
||||
}
|
||||
linearLayout.addView(ll);
|
||||
count -= 3;
|
||||
break;
|
||||
case 1:
|
||||
linearLayout.addView(getImageView(list, index, width, 1, context));
|
||||
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(list, index, width, 2, context));
|
||||
index += 1;
|
||||
}
|
||||
linearLayout.addView(ll);
|
||||
count -= 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static SimpleDraweeView getImageView(final List<String> list, final int position, int width, int type, final Context context) {
|
||||
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(context).display(list.get(position), imageView, ScalingUtils.ScaleType.CENTER_CROP, context);
|
||||
} 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(context).display(list.get(position), imageView, ScalingUtils.ScaleType.CENTER_CROP, context);
|
||||
} 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(context).display(list.get(position), imageView, ScalingUtils.ScaleType.CENTER_CROP, context);
|
||||
}
|
||||
imageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent checkIntent = new Intent(context, ViewImageActivity.class);
|
||||
checkIntent.putExtra("urls", (ArrayList<String>) list);
|
||||
checkIntent.putExtra("current", position);
|
||||
checkIntent.putExtra("ScaleType", "FIT_CENTER");
|
||||
context.startActivity(checkIntent);
|
||||
}
|
||||
});
|
||||
return imageView;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user