我有一个图库,图片尺寸相同..
在纵向中,图像占据整个屏幕并且效果很好,但在横向中,图像不会拉伸到整个屏幕,其他部分图像也会显示在同一屏幕中。
这是我使用的ImageAdapter:
public class ImageAdapter扩展BaseAdapter { int mGalleryItemBackground; int counter = 0;
private 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++;
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
i.setImageBitmap(BitmapFactory.decodeFile(mImageIds[position]));
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(mGalleryItemBackground);
return i;
}
}
xml:
<ScrollView
android:id="@+id/QuranGalleryScrollView"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<Gallery android:id="@+id/GalleryLandscape"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</Gallery>
</ScrollView>
如何使图库中的图像视图拉伸以适应屏幕? 感谢
答案 0 :(得分:4)
在getView()
方法中添加以下行:
i.setLayoutParams( new Gallery.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));
这对我来说有用,试一试!