2013-08-30 123 views

回答

1

下面的方法做你想做的。

public class AvatarImage extends ImageView { 
    Bitmap image; 
    public static final String TAG = "AvatarImage"; 

    public AvatarImage(Context context) { 
     super(context); 
     setImageResource(R.drawable.avatar); 
    } 

    /** 
    * This method takes the participant object and attempts to 
    * download avatar of the participant from google plus 
    * if this is unsuccesful default avatar is shown 
    * @param p 
    */ 
    public void setImageFromParticipant(Participant p) { 
     ImageManager im = ImageManager.create(getContext());  
     im.loadImage(this, p.getIconImageUri(), R.drawable.avatar); 
     try{ 
      Bitmap bitmap = ((BitmapDrawable)this.getDrawable()).getBitmap(); 
      setImageBitmap(bitmap); 
     } 
     catch(NullPointerException e) 
     { 
      e.printStackTrace(); 
     } 
    } 
} 
+0

不工作這個代碼!你有其他解決方案嗎? – John95

+0

對不起。這非常簡單,適用於我。如果您在將代碼集成到代碼時遇到問題,您應該更具體地瞭解它如何工作。所以我可以幫忙。 – user2259824

+0

當我寫ImageHelper時出錯。我該怎麼辦? – John95

0

如從約翰對方的回答中的代碼是正確的,但是,目前與谷歌Play業務圖書館這裏Google Issue Tracker所示爲使用版本庫中的10人(或許版本9的問題。 。版本8很好)。不幸的是,對於這個問題,如果您甚至嘗試獲取由ImageManager解碼的URI,Google Play服務將停止工作。要麼等待圖書館的下一個版本,要麼嘗試獲取版本8的版本號。 (我無法將此作爲對上述答案的評論,因此不得不用新的答案...)

+0

我看到它,我確實知道你會發生什麼:) – John95

+0

我如何將我的revision10降級到revision8? – John95

相關問題