Picasso Images are loading slow in android, why?

时光总嘲笑我的痴心妄想 提交于 2020-01-24 02:54:27

问题


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 code

 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" />


回答1:


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

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


来源:https://stackoverflow.com/questions/37399131/picasso-images-are-loading-slow-in-android-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!