2
我有一个图像库,图像大小相同
在Portrait中,图像占据整个屏幕并且效果很好,但在Landscape中,图像不伸展到整个屏幕和其他图像的部分显示也以相同的屏幕..
这里是我使用ImageAdapter:Strech ImageViews中的图库适合屏幕
公共类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>
怎么可能使画廊舒展内imageviews以适应屏幕? 感谢
哇,工作完美..谢谢:) – Omar 2011-05-01 17:31:39
如果你是Android 2.1之前的版本,请使用'FILL_PARENT'而不是'MATCH_PARENT'。 (它在Android 2.2中更名。) – 2011-08-19 20:59:14