I have a Gallery with images that are at the same size..
When in Portrait, the images take the whole screen and it works well, though in Landscape, the images arent stretching to the whole screen and parts of other images are displayed also in the same screen..
Here is the ImageAdapter I use:
public class ImageAdapter extends 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;
}
}
The 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>
How is it possible to make the imageviews inside the Gallery stretch to fit the screen?
Thanks
In your
getView()method add this line:This is what worked for me before, give it a try!