【问题标题】:CenterCrop scale type not working on image loaded with PicassoCenterCrop 比例类型不适用于用毕加索加载的图像
【发布时间】:2018-12-17 09:14:06
【问题描述】:

我正在尝试将照片(通过 url 下载)加载到图像视图中,并让它跨越其父视图的整个宽度,这是列表视图中的一行。

<ImageView
                android:id="@+id/property_row_photo"
                android:layout_width="match_parent"
                android:layout_height="@dimen/search_list_item_height"
                android:scaleType="centerCrop"
                android:adjustViewBounds="true" />

直接在 ImageView 上设置 scaleType 似乎无济于事。我知道每一行的高度,所以我正在测量宽度,然后使用它来调用 Picasso 的 Resize 和 CenterCrop 方法,如下所示:

var height = Convert.ToInt32 (ApplicationContext.Activity.Resources.GetDimension (Resource.Dimension.search_list_item_height));
viewHolder.Photo.Measure (0, height);
var width = viewHolder.Photo.MeasuredWidth;
var url = property.ThumbnailPhotoUrl.Replace ("/thumbnails/", "/{0}/{1}/".WithFormat (width, height));
viewHolder.Photo.SetUrlBitmapWithCenterCrop (url, width, height, 
                    loadingResourceId: Resource.Drawable.property_row_background,
                    errorResourceId: Resource.Drawable.image_not_available);

public static void SetUrlBitmapWithCenterCrop (this ImageView imageView, string url,
            int width, int height, int? loadingResourceId = null, int? errorResourceId = null) {
            Picasso.With (imageView.Context)
               .Load (url)
               .Placeholder (loadingResourceId ?? 0)
               .Error (errorResourceId ?? 0)
               .Resize (width, height)
               .CenterCrop ()
               .Tag (imageView.Context)
               .Into (imageView);
        }

不幸的是,centerCrop scaleType 没有被应用,我看到每张照片的左右都有大的白色边框。知道我错过了什么吗?请注意,我也尝试过 Fit 方法,但没有成功。

【问题讨论】:

    标签: android xamarin xamarin.android android-imageview picasso


    【解决方案1】:

    尝试同时使用 fit 和 centerinside

      Picasso.with(getContext()).load(path).fit().centerInside().into(iv);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-29
      • 2018-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多