网站规划的原则,网站开发都需要什么工作,阿里云服务器配置,加强政务公开与网站建设一 自定义相册 结合Glide图片库#xff0c;加载显示本地图片#xff0c;并可以实现单选#xff0c;多选#xff0c;预览功能。特点 加载最近新增图片#xff0c;GridView显示分文件夹选择图片支持单选#xff0c;多选#xff08;最大9张#xff09;支持大图预览以库的形…一 自定义相册 结合Glide图片库加载显示本地图片并可以实现单选多选预览功能。特点 加载最近新增图片GridView显示分文件夹选择图片支持单选多选最大9张支持大图预览以库的形式保存实际项目中导入PhotoSelector库使用。 二 九宫格显示图片 九宫格形式显示图片点击预览大图GirdView 设置 1 com.zc.baselib.view.NoScrollGridView2 android:idid/gv_photo3 android:layout_widthmatch_parent4 android:layout_heightwrap_content5 android:layout_gravitycenter6 android:layout_marginTopdimen/margin_min7 android:backgroundnull8 android:clickablefalse9 android:listSelectorandroid:color/transparent
10 android:verticalSpacingdimen/margin_min_a
11 android:numColumns3/ 自定义PhotoGridAdapter数据源 1 public class PhotoGridAdapter extends CommonListAdapterImageModel {2 3 private int itemWidth;4 private int gridViewWidth;5 private int horizentalNum 3;6 private AbsListView.LayoutParams itemLayoutParams;7 8 public PhotoGridAdapter(Context context, ListImageModel mDatas) {9 super(context, mDatas);
10 }
11
12 public PhotoGridAdapter(Context context, ListImageModel mDatas, int width) {
13 super(context, mDatas);
14 this.gridViewWidth width;
15 setItemWidth();
16 }
17
18 /**
19 * 设置每一个Item的宽高 (GirdView宽度 - 行间距) / 每行显示个数
20 */
21 public void setItemWidth() {
22 int horizentalSpace mContext.getResources().getDimensionPixelSize(com.zc.photoselector.R.dimen.gridview_item_horizontalSpacing_4);
23 this.itemWidth (gridViewWidth - (horizentalSpace * (horizentalNum - 1))) / horizentalNum;
24 // this.itemWidth viewWidth / horizentalNum;
25 this.itemLayoutParams new AbsListView.LayoutParams(itemWidth, itemWidth);
26 }
27
28
29 Override
30 public View getView(final int position, View view, ViewGroup viewGroup) {
31 if (view null) {
32 view View.inflate(mContext, R.layout.item_photo_grid, null);
33 view.setLayoutParams(itemLayoutParams);
34 }
35
36 ImageView img_photo ViewHolder.get(view, R.id.img_photo);
37 ImageModel imageModel mDatas.get(position);
38 Glide.with(mContext).load(imageModel.getOriginalPath())
39 .dontAnimate()
40 .centerCrop()
41 .override(300, 300)
42 .placeholder(com.zc.photoselector.R.drawable.ic_loading_white)
43 .error(com.zc.photoselector.R.drawable.mis_default_error)
44 .into(img_photo);
45
46 //查看大图
47 img_photo.setOnClickListener(new View.OnClickListener() {
48 Override
49 public void onClick(View view) {
50 Intent intent new Intent(mContext, PhotoPreviewActivity.class);
51 intent.putExtra(index, position);
52 intent.putExtra(images, (ArrayList) mDatas);
53 mContext.startActivity(intent);
54 }
55 });
56 return view;
57 }
58
59 } item_photo_grid 布局文件 1 RelativeLayout xmlns:androidhttp://schemas.android.com/apk/res/android2 android:layout_widthmatch_parent3 android:layout_heightmatch_parent4 5 ImageView6 android:idid/img_photo7 android:layout_widthfill_parent8 android:layout_heightfill_parent9 android:layout_gravitycenter
10 android:scaleTypecenterCrop /
11
12 /RelativeLayout activity引用 1 gv_photo (NoScrollGridView) findViewById(R.id.gv_photo);
2 list new ArrayList();
3 gv_photo.post(new Runnable() {
4 Override
5 public void run() {
6 adapter new PhotoGridAdapter(ServiceActivity.this, list, gv_photo.getWidth());
7 gv_photo.setAdapter(adapter);
8 }
9 }); 转载于:https://www.cnblogs.com/suiyilaile/p/9159451.html