2011-05-01 44 views
2

我有一个图像库,图像大小相同
在Portrait中,图像占据整个屏幕并且效果很好,但在Landscape中,图像不伸展到整个屏幕和其他图像的部分显示也以相同的屏幕..
这里是我使用ImageAdapter:Strech ImageViews中的图库适合屏幕

公共类ImageAdapter延伸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:

<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> 

怎么可能使画廊舒展内imageviews以适应屏幕? 感谢

回答

4

在你getView()方法添加此行:

i.setLayoutParams(new Gallery.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT)); 

这是我之前什么工作,不妨一试!

+0

哇,工作完美..谢谢:) – Omar 2011-05-01 17:31:39

+1

如果你是Android 2.1之前的版本,请使用'FILL_PARENT'而不是'MATCH_PARENT'。 (它在Android 2.2中更名。) – 2011-08-19 20:59:14