2

我在画廊中居中图像时遇到问题。我希望它们填充画廊中可用的最大空间,但不希望它们在屏幕顶部被剪切。我想看看他们的顶部而不是底部。

我的问题是如何设置位置以便我可以在图库中看到图像的“顶部”?

images.setScaleType(ImageView.ScaleType.CENTER_CROP)

将图像设置为填充所有可用空间并保持其比例。问题是我的图像比宽度更高,因此它们的顶部不可见。

我有一个自定义画廊:CustomGallery,其布局是:

android:id="@+id/photos_gallery"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fadingEdge="none"
android:spacing="0dp"

图库使用适配器:GalleryAdapter,它扩展了 BaseAdapter。它的 getView 方法如下:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView image = new ImageView(mcontext);
    image.setLayoutParams(new Gallery.LayoutParams(
        android.widget.Gallery.LayoutParams.FILL_PARENT,
        android.widget.Gallery.LayoutParams.FILL_PARENT));      
    image.setScaleType(ImageView.ScaleType.CENTER_CROP);        

    image.setImageBitmap(getImgSource(position));   

    return image;   
}
4

1 回答 1

0
images.setScaleType(ImageView.ScaleType.FIT_START)

从文档中:

计算将保持原始 src 纵横比的比例,但也将确保 src 完全适合 dst。至少一个轴(X 或 Y)将完全适合。START 将结果与 dst 的左边缘和上边缘对齐。

http://developer.android.com/reference/android/graphics/Matrix.ScaleToFit.html#START

于 2012-10-09T19:39:26.170 回答