2011-04-24 65 views
2

嘿,我有一个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的顶部..

+0

显示图库父项的布局xml – rajath 2011-04-24 17:00:32

回答

0

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

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