我能够在网格视图中管理图像之间的水平空间。但是如何减少网格视图中图像之间的垂直空间。
以下是我的代码:
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_margin="5dp">
<GridView
android:id="@+id/gridView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0dp"
android:verticalSpacing="5dp"
android:horizontalSpacing="5dp"
android:scrollingCache="true"
android:smoothScrollbar="true"
android:clipChildren="true"
android:alwaysDrawnWithCache="true"
android:numColumns="auto_fit"
android:columnWidth="70dp">
</GridView>
</LinearLayout>
获取视图方法
//---returns an ImageView view---
public View getView(int position, View convertView, ViewGroup parent)
{
ImageView imageView = null;
if (convertView == null) {
imageView = new ImageView(context);
imageView.setLayoutParams(new GridView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
imageView.setTag(position);
} else {
imageView = (ImageView) convertView;
}
if((Integer)imageView.getTag() == 0) {
Bitmap bitmap = Bitmap.createScaledBitmap(imgPic.get(position).getBitmap(), 250, 200, false);
imageView.setImageBitmap(bitmap);
}else {
FileInputStream fs = null;
//Bitmap bm;
try {
fs = new FileInputStream(new File(imgPic.get(position).getFilePath().toString()));
if(fs!=null) {
//to get the thumbnail view of the image
Bitmap scaledBitmap = decodeFile(imgPic.get(position).getFilePath().toString(), 250, 200);
imageView.setImageBitmap(scaledBitmap);
imageView.setId(position);
}
} catch (IOException e) {
e.printStackTrace();
} finally{
if(fs!=null) {
try {
fs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
return imageView;
}
decodeFile 是一个调整图像大小的函数