图库中的图像未在横向中拉伸/缩放到整个屏幕

时间:2011-04-24 15:22:52

标签: android

嘿,我在ScrollView中有一个图库,问题是在横向时,图像没有缩放以填满屏幕,这是一个截图:picture(忽略吐司)
如您所见,中间的图像是当前选择的图像,但您可以看到在屏幕的左/右侧也会显示下一个/上一个图像的部分..如何在中间显示图像中间缩放到整个屏幕?
ImageAdapter类:

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>

感谢。

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>

{我也在使用其他相对视图,因此它们显示在图库上方,尽管它位于xml的顶部..

1 个答案:

答案 0 :(得分:0)

我能够解决这个问题的唯一方法是在我的代码的getView方法中添加以下内容。

RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);                 i.setLayoutParams(的LayoutParams);