3
來自畢加索libery的圖像在點擊幾下後就會加載模擬器,速度非常慢。他們爲什麼加載速度很慢?我需要做些什麼才能使它們加載速度更快。我用png文件和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" />
您有快速的互聯網連接嗎? –