I have a list of images. I display it in the GridView using the adapter:
public View getView(int position, View convertView, ViewGroup parent) { Book book = getItem(position); ImageView preview; if (convertView == null) { // if it's not recycled, initialize some attributes preview = new ImageView(mContext); int height = Utilities.convertDpToPixels(175, mContext); int width = Utilities.convertDpToPixels(175, mContext); preview.setLayoutParams(new GridView.LayoutParams(width, height)); preview.setPadding(8, 8, 8, 8); preview.setImageResource(R.drawable.ic_launcher_background); } else { preview = (ImageView) convertView; } preview.setId(position); Bitmap bitmap = Utilities.loadImageFromStorage(book.getPath(), book.getTitle()); preview.setAdjustViewBounds(true); preview.setImageBitmap(bitmap); return preview; The problem is that I need the same cells, and after inserting a Bitmap there, they change their size to the size of a Bitmap. How can I fix the dimensions of View. Image to be cropped in the center. I thought to use the method of manually cutting the picture, but it will increase the process of loading the list.
int height = Utilities.convertDpToPixels(175, mContext); int width = Utilities.convertDpToPixels(175, mContext); preview.setLayoutParams(new GridView.LayoutParams(width, height));int height = Utilities.convertDpToPixels(175, mContext); int width = Utilities.convertDpToPixels(175, mContext); preview.setLayoutParams(new GridView.LayoutParams(width, height));- Ponomarenko OlehImageView. Honestly, I didn’t read this code, but most likely the element has awrap_contentparameter. What prevents to pre-set its size? - ahgpougImageViewand form it in the center, but in general, trim it in any way you like. + there will be no large memory leaks. - ahgpoug