【问题标题】:Setting custom position of CENTER.CROP images in gallery. Cutting bottom part of image instead of top one在图库中设置 CENTER.CROP 图像的自定义位置。剪切图像的底部而不是顶部
【发布时间】:2012-10-09 19:28:10
【问题描述】:

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

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

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

【问题讨论】:

    标签: android android-layout android-imageview android-gallery


    【解决方案1】:
    images.setScaleType(ImageView.ScaleType.FIT_START)
    

    来自文档:

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

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

    【讨论】:

    猜你喜欢
    • 2018-09-20
    • 2011-09-23
    • 1970-01-01
    • 2021-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-15
    • 1970-01-01
    相关资源
    最近更新 更多