毕加索图片在Android中加载缓慢,为什么? [英] Picasso Images are loading slow in android, why?

查看:78
本文介绍了毕加索图片在Android中加载缓慢,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几次点击后,毕加索自由影像中的图像就会加载到仿真器中,而且速度非常慢.为什么加载这么慢?我该怎么做才能使它们加载更快.我尝试了png文件和jpg.

The images from the Picasso libery are loading in the emulater after a few clicks and very slow. Why are they loading so slow? And what do I have to do to make them load faster. I tried it with png files and jpg.

Java代码

 private int a;
 ImageView ivImageFromUrl;


 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ivImageFromUrl=(ImageView)findViewById(R.id.iv_image_from_url);

}

 public void buttonOnClick(View v)  {
    // do something when the button is clicked
    Button button = (Button) v;

    a = (byte) (Math.random() * 5);

    switch (a) {
        case 1:
            Picasso.with(getApplicationContext()).load("http://icons.iconarchive.com/icons/crountch/one-piece-jolly-roger/72/Luffys-flag-2-icon.png").into(ivImageFromUrl);
          break;
        case 2:
            Picasso.with(getApplicationContext()).load("http://i40.tinypic.com/2i8xait.jpg").into(ivImageFromUrl);
            break;
        case 3:
            Picasso.with(getApplicationContext()).load("http://i41.tinypic.com/2i8xahh.jpg").into(ivImageFromUrl);
            break;
        case 4:
            Picasso.with(getApplicationContext()).load("http://i42.tinypic.com/2i8xahk.jpg").into(ivImageFromUrl);
            break;
        case 5:
            Picasso.with(getApplicationContext()).load("http://i40.tinypic.com/2i8xagp.jpg").into(ivImageFromUrl);
            break;
    }
}
}

XML

  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    android:id="@+id/textView2" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Image text"
    android:id="@+id/textView"
    android:layout_below="@+id/textView2"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="82dp" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Image"
    android:id="@+id/button"
    android:onClick="buttonOnClick"
    android:layout_below="@+id/textView"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="41dp" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/iv_image_from_url"
    android:layout_alignParentBottom="true"
    android:layout_alignRight="@+id/textView"
    android:layout_alignEnd="@+id/textView"
    android:layout_marginBottom="106dp" />

推荐答案

如果图像太大,则可能需要一些时间.

If your images are too large, then it may take some time.

如果您需要显示个人资料图片(在您的布局中尺寸为350x350),那么为什么要加载完整图片.根据您的要求调整图像大小.

If you need to show profile picture, whose size in your layout is 350x350, then why load full image. Re-size the image as per your requirement.

Picasso.with(getApplicationContext()).load(filePath).resize(400,400).centerCrop().into(imageView);

这篇关于毕加索图片在Android中加载缓慢,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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