我使用Picasso下载我从列表视图中显示的网络服务中获取的图像。 它适用于运行kitkat 5+以上的设备。 在kitkat中,它无法加载一些图像。
我的配置设置如下
android {
compileSdkVersion 24
buildToolsVersion '24.0.0'
defaultConfig {
applicationId ""
minSdkVersion 17
targetSdkVersion 24
}
}
dependencies {
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:design:24.0.0'
}
我在listAdapter中调用Picasso
Picasso.with(main)
.load(main.articles.get(position).image)
.into(holder.image);
我的布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#fff"
>
<ImageView
android:id="@+id/articleimage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:paddingBottom="5dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:layout_alignParentTop="true"
/>
<TextView
android:id="@+id/categoryname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:textSize="26dp"
android:layout_below="@id/articleimage"
android:layout_alignParentStart="true"
android:layout_marginTop="280dp"
android:layout_alignParentTop="true"
android:textColor="#ff48b0"
android:background="#FFFFFF"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:textStyle="bold"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/title"
android:gravity="center_vertical"
android:paddingStart="10dp"
android:paddingBottom="5dp"
android:clickable="false"
android:textColor="#3D3838"
android:textStyle="bold"
android:textSize="33dp"
android:focusable="false"
android:layout_below="@id/articleimage"
android:layout_marginTop="8dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="122dp"
android:id="@+id/excerpt"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textSize="26dp"
android:lineSpacingExtra="8dp"
android:textColor="#4c4d4e"
android:layout_below="@id/title"
/>
</RelativeLayout>
我的日志
Settings: Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
08-11 06:30:19.406 28898-28898/com.s W/System.err: com.squareup.picasso.Downloader$ResponseException: 404 Not Found
08-11 06:30:19.406 28898-28898/com.s W/System.err: at com.squareup.picasso.UrlConnectionDownloader.load(UrlConnectionDownloader.java:96)
08-11 06:30:19.406 28898-28898/com.s W/System.err: at com.squareup.picasso.NetworkRequestHandler.load(NetworkRequestHandler.java:47)
08-11 06:30:19.406 28898-28898/com.s W/System.err: at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:206)
08-11 06:30:19.406 28898-28898/com.s W/System.err: at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:159)
08-11 06:30:19.406 28898-28898/com.s W/System.err: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
08-11 06:30:19.406 28898-28898/com.s W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
08-11 06:30:19.406 28898-28898/com.s W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
08-11 06:30:19.406 28898-28898/com.s W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
08-11 06:30:19.406 28898-28898/com.s W/System.err: at java.lang.Thread.run(Thread.java:841)
08-11 06:30:19.406 28898-28898/com.s W/System.err: at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:411)
"Picasso-/wp-content/uploads/Vous-consommez-chaque-jour-cet-aliment-qui-endommage-votre-cerveau-et-votre-foie.jpg" prio=5 tid=613 RUNNABLE
08-11 06:52:44.326 28898-18174/com.s I/dalvikvm: | group="main" sCount=0 dsCount=0 obj=0xb20862a8 self=0xb98f6fd0
08-11 06:52:44.326 28898-18174/com.s I/dalvikvm: | sysTid=18174 nice=10 sched=3/0 cgrp=[fopen-error:2] handle=-1186417376
08-11 06:52:44.326 28898-18174/com.s I/dalvikvm: | state=R schedstat=( 0 0 0 ) utm=2 stm=1 core=0
08-11 06:52:44.326 28898-18174/com.s I/dalvikvm: at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
08-11 06:52:44.326 28898-18174/com.s I/dalvikvm: at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:613)
08-11 06:52:44.326 28898-18174/com.s I/dalvikvm: at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:589)
08-11 06:52:44.326 28898-18174/com.s I/dalvikvm: at com.squareup.picasso.BitmapHunter.decodeStream(BitmapHunter.java:142)
08-11 06:52:44.326 28898-18174/com.s I/dalvikvm: at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:217)
08-11 06:52:44.326 28898-18174/com.s I/dalvikvm: at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:159)
08-11 06:52:44.326 28898-18174/com.s I/dalvikvm: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
08-11 06:52:44.326 28898-18174/com.s I/dalvikvm: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
08-11 06:52:44.326 28898-18174/com.s I/dalvikvm: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
08-11 06:52:44.326 28898-18174/com.s I/dalvikvm: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
08-11 06:52:44.326 28898-18174/com.s I/dalvikvm: at java.lang.Thread.run(Thread.java:841)
08-11 06:52:44.326 28898-18174/com.s I/dalvikvm: at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:411)
08-11 06:52:44.346 28898-18174/com.s D/skia: --- decoder->decode returned false
08-11 06:52:44.366 28898-28898/com.s W/System.err: java.lang.RuntimeException: ===============BEGIN PICASSO STATS ===============
08-11 06:52:44.366 28898-28898/com.s W/System.err: Memory Cache Stats
08-11 06:52:44.366 28898-28898/com.ss W/System.err: Max Cache Size: 9586980
08-11 06:52:44.366 28898-28898/com.s W/System.err: Cache Size: 0
08-11 06:52:44.366 28898-28898/com.s W/System.err: Cache % Full: 0
08-11 06:52:44.376 28898-28898/com.s W/System.err: Cache Hits: 0
08-11 06:52:44.376 28898-28898/com.s W/System.err: Cache Misses: 1
08-11 06:52:44.376 28898-28898/com.s W/System.err: Network Stats
08-11 06:52:44.376 28898-28898/com.s W/System.err: Download Count: 0
08-11 06:52:44.376 28898-28898/com.s W/System.err: Total Download Size: 0
08-11 06:52:44.376 28898-28898/com.s W/System.err: Average Download Size: 0
08-11 06:52:44.376 28898-28898/com.s W/System.err: Bitmap Stats
08-11 06:52:44.376 28898-28898/com.s W/System.err: Total Bitmaps Decoded: 0
08-11 06:52:44.376 28898-28898/com.s W/System.err: Total Bitmap Size: 0
08-11 06:52:44.376 28898-28898/com.s W/System.err: Total Transformed Bitmaps: 0
08-11 06:52:44.376 28898-28898/com.s W/System.err: Total Transformed Bitmap Size: 0
08-11 06:52:44.376 28898-28898/com.s W/System.err: Average Bitmap Size: 0
08-11 06:52:44.376 28898-28898/com.s W/System.err: Average Transformed Bitmap Size: 0
08-11 06:52:44.376 28898-28898/com.s W/System.err: ===============END PICASSO STATS ===============
08-11 06:52:44.376 28898-28898/com.s W/System.err: at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:180)
08-11 06:52:44.376 28898-28898/com.s W/System.err: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
08-11 06:52:44.376 28898-28898/com.s W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
08-11 06:52:44.376 28898-28898/com.s W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
08-11 06:52:44.376 28898-28898/com.s W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
08-11 06:52:44.376 28898-28898/com.s W/System.err: at java.lang.Thread.run(Thread.java:841)
08-11 06:52:44.376 28898-28898/com.s W/System.err: at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:411)
08-11 06:52:44.376 28898-28898/com.s W/System.err: Caused by: java.lang.OutOfMemoryError
08-11 06:52:44.376 28898-28898/com.s W/System.err: at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
08-11 06:52:44.376 28898-28898/com.s W/System.err: at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:613)
08-11 06:52:44.376 28898-28898/com.s W/System.err: at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:589)
08-11 06:52:44.376 28898-28898/com.s W/System.err: at com.squareup.picasso.BitmapHunter.decodeStream(BitmapHunter.java:142)
08-11 06:52:44.376 28898-28898/com.s W/System.err: at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:217)
08-11 06:52:44.376 28898-28898/com.s W/System.err: at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:159)
08-11 06:52:44.376 28898-28898/com.s W/System.err: ... 6 more