如何使下滑显示如毕加索? [英] How to make glide display like picasso?

查看:213
本文介绍了如何使下滑显示如毕加索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用了毕加索的库加载图像到我的GridView在我的应用程序,它的工作原理,准确地看起来,我想,但用户告诉我,图像加载速度非常慢,我知道,这是因为网络的差速度和毕加索加载我的完整图像,这是非常大的,然后调整他们适合我的图像视图,所以我尝试使用它加载图像几乎两倍的速度,但对某些图像它不保存像毕加索的结构确实例如毕加索滑翔加载图像看起来像

此

虽然下滑加载它们具有不同的状态这里就是它加载最初

第一州

,然后滚动后,它看起来像

此

然后最终大量的滚动后,它看起来像

此

我是pretty相信,这是由于我的图像尺寸全部为不同的,也似乎让我的占位符图像大小不同有效果,但我想知道的是我如何才能滑行保持其初始状态,或者我如何获得毕加索加载更快?我听说从降低888颜色格式565有一个戏剧性的效果,任何人可以借我有两分钱?感谢您的任何和所有的建议

修改

这是我的ImageView

 < ImageView的
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:scaleType =fitXY
    机器人:ID =@ + ID / ImageView的/>

这是我如何打电话毕加索

  Picasso.with(getActivity())
                .load(mThumbIds [位置])
                .placeholder(R.drawable.placeholder)
                。适合()
                .into(ImageView的);        返回ImageView的;

和我这是怎么现在打电话滑行

  Glide.with(getActivity())
                .load(mThumbIds [位置])
                .asBitmap()
                .placeholder(R.drawable.placeholder)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .fitCenter()
                .error(R.drawable.ic_photos)
                .into(ImageView的);         返回ImageView的;

如果它重要,这是我的GridView

 < GridView控件
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:layout_margin =5DP
    机器人:ID =@ + ID / GridView控件
    机器人:为numColumns =2
    机器人:比重=中心
    机器人:drawSelectorOnTop =真
    机器人:listSelector =@绘制/波纹
    机器人:stretchMode =columnWidth时
    >


解决方案

在默认情况下,滑翔会尝试保持图像的长宽比。当您使用 fitCenter(),这意味着你想整个图像可见和​​可利用区的中心。切换到 centerCrop()将在确保图像都充满高度和宽度提供给它的第一步。

不过,你也运行到一个长期问题与 GridView控件:它假设所有列具有相同的高度。然而,您可以使用 WRAP_CONTENT 的ImageView 的高度,使每个元素得到调整大小不同会根据输入的高度(记住,滑翔的角度来看,你说你的的ImageView ,因为它需要是可以一样高!)。

如果你有一个主导的纵横比(例如,16:9),你可以使用一个固定的长宽比视图如的这将始终使用基于列的宽度相同的高度此AspectRatioImageView (由 GridView控件设置)。另外,比较复杂,选项是切换到 RecyclerView 并使用<一href=\"https://developer.android.com/reference/android/support/v7/widget/StaggeredGridLayoutManager.html\"相对=nofollow> StaggeredGridLayoutManager ,这将让你保持每个图像的长宽比和错开行,确保每个图像填充空间,并保持其高宽比。

I've been using Picasso's library to load images into my gridview in my application and it works and looks exactly as I'd like but users are telling me that the images load very slowly I know that this is because of poor network speed and Picasso is loading my full images which are very big and then resizing them to fit my image view so I tried using glide which loads the images in almost twice the speed but on some images it's not keeping the structure like Picasso does for example Picasso loading images looks like

Whilst glide loading them has different states here's what it loads initially

and then after scrolling it looks like

and then eventually after lots of scrolling it looks like

I am pretty confident that this is due to my images sizes all being different and also it seems that making my placeholder image a different size has an effect but what I want to know is how do I get glide to keep its initial state, or how do I get Picasso to load quicker? I've heard lowering the color format from 888 to 565 has a dramatic effect, can anybody lend me there two cents? Thanks for any and all suggestions

EDIT

this is my imageview

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scaleType="fitXY"
    android:id="@+id/imageView"/>

this is how i was calling picasso

                 Picasso.with(getActivity())
                .load(mThumbIds[position])
                .placeholder(R.drawable.placeholder)
                .fit()
                .into(imageView);

        return imageView;

and this is how i am now calling glide

                 Glide.with(getActivity())
                .load(mThumbIds[position])
                .asBitmap()
                .placeholder(R.drawable.placeholder)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .fitCenter()
                .error(R.drawable.ic_photos)
                .into(imageView);

         return imageView;

and if it matters this is my gridview

    <GridView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_margin="5dp"
    android:id="@+id/gridview"
    android:numColumns="2"
    android:gravity="center"
    android:drawSelectorOnTop="true"
    android:listSelector="@drawable/ripple"
    android:stretchMode="columnWidth"
    >

解决方案

By default, Glide will attempt to keep the aspect ratio of the images. When you use fitCenter(), this implies that you want the whole image visible and centered within the available area. Switching to centerCrop() would be the first step in making sure the image fills both the height and width available to it.

However, you are also running into a longstanding issue with GridView: it assumes all columns have the same height. Yet, you use wrap_content for your ImageView's height, causing each element to get resized differently based on the incoming height (remember, to Glide's perspective, you said your ImageView can be as tall as it needs to be!).

If you have a dominant aspect ratio (say, 16:9), you could use a fixed aspect ratio view such as this AspectRatioImageView which would always use the same height based on the width of the column (set by your GridView). Another, more complicated, option is to switch to RecyclerView and use a StaggeredGridLayoutManager, which would allow you to keep the aspect ratio of each image and stagger the rows, ensuring that each image fills the space and keeps its aspect ratio.

这篇关于如何使下滑显示如毕加索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆