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