在我的活动中,我必须展示一些图像。我在我的活动中使用了 gridview,每行应该显示 4 个图像(每个图像的宽度是屏幕的 25%)。我需要减小与宽度相同大小的图像的高度。
所以,在我的 UI 中,我有一个 gridview,我的 imageAdapter 将图片排列到屏幕上。这是适配器的代码:
public class ContestantsPhotoAdapter extends BaseAdapter {
private LayoutInflater myInflater;
private Bitmap[] bitmapList;
public ContestantsPhotoAdapter(Context c) {
myInflater = LayoutInflater.from(c);
}
public void setData(Bitmap[] bmImages){
bitmapList = bmImages;
Log.i("ContestantsPhotoAdapter", "Images passed to the adapter.");
}
@Override
public int getCount() {
return bitmapList.length;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder holder;
if (convertView == null) {
convertView = myInflater.inflate(R.layout.grid_contestantsphoto, null);
holder = new ViewHolder();
holder.ivIcon = (ImageView) convertView.findViewById(R.id.imvContestantsPhoto_icon);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.ivIcon.setImageBitmap(bitmapList[position]);
return convertView;
}
static class ViewHolder {
ImageView ivIcon;
}
}
grid_contestantsphoto.xml 是:
<?xml version="1.0" encoding="utf-8"?>
<ImageView
xmlns:android = "http://schemas.android.com/apk/res/android"
android:id = "@+id/imvContestantsPhoto_icon"
android:layout_width = "wrap_content"
android:layout_height = "100dip"
android:contentDescription = "@string/menu_contentdescription" />
我的问题是当我更改时android:layout_height = "100dip"
它不会生效,并且高度总是和以前一样。
请告诉我如何减小尺寸。谢谢你。