Picasso centerCrop and fit得到不同的结果

时间:2016-09-07 14:09:36

标签: java android image picasso

我想将图像插入到ImageView中,后者用作背景。此背景位于RecyclerView中。当它第一次加载时,它看起来像这样:

enter image description here

但是当我滚动到另一个项目并向后滚动时,它看起来像这样(它应该总是这样):

enter image description here

我在这里添加图片:

public static async void Main(string[] args)
{
    var urlAddress = "http://mywebsite.com/msexceldoc.xlsx";
    var fileName = @"D:\1.xlsx";

    using (var client = new WebClient())
    {
        await client.DownloadFileTaskAsync(new Uri(urlAddress), fileName);
    }
}

这就是图像本身:

 public void onBindViewHolder(StoryViewHolder holder, int position) {
    holder.cardView.setMinimumHeight(height/3);
    holder.layout.setMinimumHeight((int) ((float) width / 4));
    //set image

    Picasso.with(activity).load(MainPostAdapter.URL + 140 + ".png").
            transform(new BlurTransform(holder.background.getContext())).fit().centerCrop().into(holder.background);
    holder.background.setAlpha(0.25f);
}

问题是什么?

编辑: 整个XML(它没有显示所有代码。这里也是pastebin:http://pastebin.com/8rJvSx7V):

<ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/story_view_background"/>

    

 <?xml version="1.0" encoding="utf-8"?>

1 个答案:

答案 0 :(得分:1)

尝试为android:layout_height="150dp"设置CardView(不要使用px!)。它的子FrameLayout是不必要的(CardView正在扩展FrameLayout并设置相同的属性集),将其删除。

写得不是很好,除了图片和文字视图之外,你的View所有match_parent都设置了RecyclerView ...你的项目可能正在尝试{{1}在这种情况下高度(&#34;整个屏幕&#34;)并且在第一次没有图像的情况下进行测量(毕加索异步下载,在已经测量视图时设置图像)。但是当你再次给View充气(滚动和回收)时,新列表项的测量方式会有所不同,因为Picasso会在运行时&#34;中插入你的图像,不需要异步提取(缓存)