2011-04-24 68 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);