Hey, I have a Gallery in a ScrollView, the problem is that when in Landscape, the images are not scaled to fill the screen, Here is a screenshot:
(ignore the toast)
As you can see the image in the middle is the one that is currently selected, but you can see that in the left/right sides of the screen parts of the next/previous images are also displayed.. how can I make the image in the middle get scaled to the whole screen?
ImageAdapter class:
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;
}
}
xml:
</Gallery>
<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>
Thanks.
Edit1:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/relative">
<Gallery android:id="@+id/Gallery"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</Gallery>
<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>
<....other relative views here....>
</RelativeLayout>
{I’m also using other Relative views so they get displayed above the gallery, though this is at the top of xml..
The only way I was able to fix this was to add the following in the getView method of my code.
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
i.setLayoutParams(layoutParams);