I programmatically created a gridview of images to be used inside the dialog box. If I set the columns to autofit, I always get exactly two columns, regardless of image size and any screen size. If I force the columns to a fixed number, then it works, but I can not avoid the coincidence of images at certain screen sizes, so automatic control of the number of columns would be much better. Moreover, when I try to set the stretch, it just shows nothing!
My ImageAdapter:
public class ImageAdapter extends BaseAdapter { private Context mContext; // Constructor public ImageAdapter(Context c){ mContext = c; } public int getCount() { return (IconC.Res.length); } public Object getItem(int position) { return (IconC.Res[position]); } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { ImageView imageView; if (convertView == null) { imageView = new ImageView(mContext); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setLayoutParams(new GridView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); } else { imageView = (ImageView) convertView; } imageView.setImageResource(IconC.Res[position]); return (imageView); } }
And the function that creates the dialog (which is called elsewhere with .show ())
private void createPopUp() { d_icons = new Dialog(this); GridView gv_icons = new GridView(this);
Can anyone understand why this is happening? Thanks!
Here's what it looks like with 4 fixed columns: i50.tinypic.com/2ebdfec.png
Here's how to do this with auto-detection: i50.tinypic.com/25jxo9s.png
Here is a layout with auto-detection on a horizontal tab: i49.tinypic.com/23r7qj5.png
Beppi's
source share