@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private static ImageSize getImageViewSize(ImageView imageView) { ImageSize imageSize = new ImageSize(); DisplayMetrics displayMetrics = imageView.getContext().getResources().getDisplayMetrics(); ViewGroup.LayoutParams lp = imageView.getLayoutParams(); /* * 获取图片压缩的宽和高 * */ int width = imageView.getWidth(); // 获取imageView的实际宽度 if (width <= 0) { width = lp.width; // 获取imageView在布局中设置的宽度 } if (width <= 0) { width = imageView.getMaxWidth(); } if (width <= 0) { width = displayMetrics.widthPixels; } imageSize.width = width; int height = imageView.getHeight(); // 获取imageView的实际宽度 if (height <= 0) { height = lp.height; // 获取imageView在布局中设置的宽度 } if (height <= 0) { height = imageView.getMaxHeight(); } if (height <= 0) { height = displayMetrics.heightPixels; } imageSize.height = height; return imageSize; }
@Override public View getView(int position, View convertView, ViewGroup parent) { View view = getItemView(convertView, parent); final Selfie selfie = selfies.get(position); TextView textView = (TextView) view.findViewById(R.id.file_name_text_view); textView.setText(selfie.getImageFileName()); ImageView imageView = (ImageView) view.findViewById(R.id.thumbnail_image_view); imageView.setImageBitmap( selfie.getThumbnail(imageView.getMaxWidth(), imageView.getMaxHeight())); view.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(context, ViewSelfieActivity.class); intent.putExtra(ViewSelfieActivity.SELECTED_SELFIE, selfie); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } }); return view; }