Android,如何降低图像适配器中图像的高度?
在我的活动中,我必须展示一些图片。我在活动中使用了gridview,每行应该显示4个图像(每个图像的宽度是屏幕的25%)。我需要减少高度的图像在相同的大小与宽度 所以,在我的UI中,我有一个gridview,我的imageAdapter将图片排列到屏幕中。这是适配器的代码:Android,如何降低图像适配器中图像的高度?,android,gridview,height,imageview,Android,Gridview,Height,Imageview,在我的活动中,我必须展示一些图片。我在活动中使用了gridview,每行应该显示4个图像(每个图像的宽度是屏幕的25%)。我需要减少高度的图像在相同的大小与宽度 所以,在我的UI中,我有一个gridview,我的imageAdapter将图片排列到屏幕中。这是适配器的代码: public class ContestantsPhotoAdapter extends BaseAdapter { private LayoutInflater myInflater; private B
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_materialsphoto.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\u height=“100dip”时,它不会生效,并且高度始终与以前相同
请告诉我如何缩小尺寸。谢谢。这真的对我有用!请试试这个
<ImageView
android:id="@+id/productImage"
android:layout_width="100px"
android:layout_height="100px"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:scaleType="fitCenter"
android:layout_marginRight="10dip"
android:adjustViewBounds="true"
android:src="@drawable/loading" />
以备将来参考。我将适配器代码更改为:
public void setData(Bitmap[] bmImages){
bitmapList = bmImages;
for(int i=0; i < bitmapList.length; i++){
bitmap = bitmapList[i];
bitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth(), bitmap.getWidth(), false);
bitmapList[i] = bitmap;
}
Log.i("ContestantsPhotoAdapter", "Images passed to the adapter.");
}
public void setData(位图[]bmImages){
位图列表=bmImages;
对于(int i=0;i
现在,图像的高度与宽度相同。谢谢,但不幸的是,没有起作用。静止高度和原来一样。再次感谢,但我认为这不是正确的方式,因为没有任何效果。