我有一个横向模式的图库,其中包含很多带有imageadapter的图像.我希望图像水平延伸到整个屏幕,并保持纵横比并根据需要垂直延伸.
我尝试使用FIT_XY,它在水平方向上不适合,但不能垂直保持比例(图像被压碎)
我怎样才能做到这一点?这是自定义图像适配器:
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
int counter = 0;
private final Context mContext;
public String[] mImageIds;
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = c.obtainStyledAttributes(R.styleable.Gallery1);
mGalleryItemBackground = a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
public void insert(String string) {
mImageIds[counter] = string;
counter++;
}
@Override
public int getCount() {
return mImageIds.length;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
i.setImageBitmap(BitmapFactory.decodeFile(mImageIds[position]));
i.setLayoutParams(new Gallery.LayoutParams(WindowManager.LayoutParams.FILL_PARENT, WindowManager.LayoutParams.FILL_PARENT));
i.setScaleType(ImageView.ScaleType.MATRIX);
i.setBackgroundResource(mGalleryItemBackground);
return i;
}
}
解决方法:
当我在android中执行此操作时,我使用了fit缩放比例(fitCenter,fitStart,fitEnd)以及Adjust视图范围,xml属性将是例如
android:scaleType="fitCenter" android:adjustViewBounds="true"