我想制作一个包含 75dp 宽度和 75dp 高度的图像视图的 GridView。而且我希望这个正方形填充屏幕大小,中间没有空格。现在我只使用 500 计数。所以它随机打印500个正方形图像。它没有填满空间。请查看下图了解平板电脑版本。
这是我的适配器:
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return 500;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some
// attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(75, 75));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(0, 0, 0, 0);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(R.drawable.sample_0);
return imageView;
}
}