2017-11-08 3 views
0

マイXMLコードピカソ、時々

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
<ImageView 
    android:id="@+id/ip_userpic" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@color/whiteColor" 
    android:src="@drawable/buddy_menu_icon" /> 
<TextView 
    android:id="@+id/ip_name" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="10dp" 
    android:text="@string/ip_name_placeholder" /> 
<Button 
    android:id="@+id/ip_follow" 
    style="@style/Widget.AppCompat.Button.Borderless.Colored" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@color/colorBackground" 
    android:contentDescription="@string/ip_follow_button" 
    android:text="@string/ip_follow_button" /> 
</LinearLayout> 

このXMLはrecyclerviewに単一の行項目をロードします。 recyclerView.Adapterのコードは次の通り私のBuddyViewクラスのコードがある

@Override 
public void onBindViewHolder(final BuddyView fellowBuddy, int position) { 
    ---------------- * other code * -----  
Uri uriBuddy = Uri.parse(buddyThis.getPhotoUrl()); 
Picasso.with(contextFRVA).setLoggingEnabled(true);//Todo: Debug profile photo random behaviour 
Picasso.with(contextFRVA).load(uriBuddy).into(fellowBuddy.userPhoto); 
    ---------------- * other code * ----- 
     } 

を下回っている:

class BuddyView extends RecyclerView.ViewHolder { 

    CircleImage userPhoto; 
    TextView userName; 
    String userID; 
    Button buttonFollow; 

    BuddyView (View itemView) { 
     super(itemView); 
     this.userPhoto = itemView.findViewById(R.id.ip_userpic); 
     this.userName = itemView.findViewById(R.id.ip_name); 
     this.buttonFollow = itemView.findViewById(R.id.ip_follow); 
    } 
} 

を今私はピカソのログをオンにしておりますので、それは以下のステートメントをログに記録されます

11-08 17:08:17.220 8701-8701/me.buddy.buddy D/Picasso: Main  created  [R1] Request{https://lh3.googleusercontent.com/-cNRNYVLKaPE/AAAAAAAAAAI/AAAAAAAAFLM/5KchSe2cA7Y/s96-c/photo.jpg} 
11-08 17:08:17.220 8701-8962/me.buddy.buddy D/Picasso: Dispatcher enqueued  [R1]+4ms 
11-08 17:08:17.230 8701-9237/me.buddy.buddy D/Picasso: Hunter  executing [R1]+5ms 
11-08 17:08:17.240 8701-8701/me.buddy.buddy D/Picasso: Main  created  [R2] Request{https://lh3.googleusercontent.com/-cNRNYVLKaPE/AAAAAAAAAAI/AAAAAAAAFLM/5KchSe2cA7Y/s96-c/photo.jpg} 
11-08 17:08:17.240 8701-8962/me.buddy.buddy D/Picasso: Hunter  joined  [R2]+1ms to [R1]+19ms, [R2]+1ms 
11-08 17:08:17.240 8701-9237/me.buddy.buddy D/Picasso: Hunter  decoded  [R1]+20ms 
11-08 17:08:17.240 8701-8962/me.buddy.buddy D/Picasso: Dispatcher batched  [R1]+21ms, [R2]+4ms for completion 
11-08 17:08:17.440 8701-8962/me.buddy.buddy D/Picasso: Dispatcher delivered [R1]+222ms, [R2]+205ms 
11-08 17:08:17.460 8701-8701/me.buddy.buddy D/Picasso: Main  completed [R1]+239ms from DISK 
11-08 17:08:17.460 8701-8701/me.buddy.buddy D/Picasso: Main  completed [R2]+223ms from DISK 

すべてが順序であるように思わ、まだ写真はありません最初のインスタンスで、ImageViewのにロードされていません。しかし、私がその活動から遠ざかり、戻ってきたり、画面が消えて再び戻ってくると、イメージは適切な場所にあります。だから、いつでも活動が再開されているようだ、写真が表示されています。しかし、それは最初のインスタンス自体に読み込まれていません。

imageviewの "wrap_content"を固定幅に変更しようとしましたが、これと同じ動作です。

私は間違っていることを正確に把握することができません。誰もが上記のコードを見て、私が試すことができるいくつかの選択肢を提案するのに役立つことができますか?

多くの方に助けてください。あなたがここで見るとおり

+0

あなたの画像を確認しましたか?uriは有効ですか?ピカソはイメージビューに束縛されません。 –

+0

@HemantParmar - はい、有効なURIです。私がそれを読み込んだとき、私はアクティビティから離れて –

答えて

0

のようなものです

public RequestCreator load(String path) { 
    if (path == null) { 
    return new RequestCreator(this, null, 0); 
    } 
    if (path.trim().length() == 0) { 
    throw new IllegalArgumentException("Path must not be empty."); 
    } 
     return load(Uri.parse(path)); 
} 

そして、あなたの質問について、あなたは(memoryPolicyを試してみました)私は最終的にこの答えを見つけました。私はfetchを使って、アプリのバックグラウンドで重要な画像のほとんどをプリロードしています。これにより、アクティビティがロードされた状態でピカソがイメージを読み込んでいて、数秒間(または時には永遠に)プレースホルダイメージを表示している状況に陥っていないことが保証されます。典型的な例は、この悪名高いいくつかの画像は、優れたユーザー体験になりプリロードするためにフェッチ使用して、ピカソの優れたキャッシングおよび画像の読み込み能力を考えると

Picasso.with(getBaseContext()).load(tempUser.getPhotoUrl()).fetch(); 

です。

1

代わりURI

ピカソライブラリからこのコードの文字列を直接使用することができます。

Picasso.with(contextFRVA).load(uriBuddy).memoryPolicy(MemoryPolicy.NO_CACHE).into(fellowBuddy.userPhoto); 
+0

に戻り、さらにPicasa.with(contextFRVA).load(uriBuddy).placeholderのようなユーザーエクスペリエンスのために.placeholder()と.error (R.drawable.placeholder).error(R.drawable.error).memoryPolicy(MemoryPolicy.NO_CACHE).into(fellowBuddy.userPhoto); –

+0

私はあなたの提案 –

+0

に従うとプレースホルダードロアブルをロードし続けますが、これはイメージをまだダウンロードしていることを意味します。イメージのサイズは? –