我能够在网格视图中管理图像之间的水平空间。但是如何在网格视图中减少图像之间的垂直空间。
以下是我的代码:
<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>
getView方法
//---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是一个调整图像大小的功能
答案 0 :(得分:3)
您使用属性android:horizontalSpacing="5dp"
,减少其值。