本文介绍了在gridview的ImageView的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我按照本指南使用网格视图中插入一个画廊图象:
I follow this guide to insert images in a gallery using grid view: http://developer.android.com/guide/topics/ui/layout/gridview.html
我编辑的imageadapter code如下:
I edited the imageadapter code as follow:
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
@Override
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.setId(R.id.img_gallery);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
// references to our images
private int[] mThumbIds = {R.drawable.itinerario1_1, R.drawable.itinerario1_1, R.drawable.itinerario1_1, R.drawable.itinerario1_1, R.drawable.itinerario1_1, R.drawable.itinerario1_1, R.drawable.itinerario1_1, R.drawable.itinerario1_1, R.drawable.itinerario1_1, R.drawable.itinerario1_1};
}
这是img_gallery XML
and this is img_gallery xml
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/img_gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:adjustViewBounds="true"/>
和这是主要的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:fadingEdge="none">
<GridView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:verticalSpacing="0dp"
android:horizontalSpacing="0dp"
android:stretchMode="columnWidth"
android:numColumns="2"
android:gravity="center"
android:padding="5dp"
/>
问题是,当我囤的应用程序,ImageView的有很多的顶部和底部填充的。我还试图将其设置为0在XML,但它不会改变。
the problem is that when i tun the app, imageview has a lot of top and bottom padding. I also tried to set it to 0 in the xml but it doesn't change.
推荐答案
您是在运行时设置填充 -
You are setting the padding on runtime-
删除此行 -
imageView.setPadding(8, 8, 8, 8);
这篇关于在gridview的ImageView的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!