开发者

QuickContactBadge in ListView

开发者 https://www.devze.com 2023-03-18 03:15 出处:网络
I have a ListView which dynamically adds QuickContactBadge and a TextView to show contact names and their photo in QuickContactBadge. I am using the following code to show photo in QuickContactBadge..

I have a ListView which dynamically adds QuickContactBadge and a TextView to show contact names and their photo in QuickContactBadge. I am using the following code to show photo in QuickContactBadge...

public static Bitmap loadContactPhoto(ContentR开发者_JS百科esolver cr, long  id) { 
     Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id); 
     InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(cr, uri);

      if (input == null) {  
       return null;    
      }
      return BitmapFactory.decodeStream(input);
     } 

Then i am calling this method by saying

quickContactBadge.setImageBitmap(loadContactPhoto(getContentResolver(), contactId));

I have following problem

1) The image is getting displayed, but it is huge. how to control size of quickcontactbadge. 2) Is this the best way to show image of a contact in quickContactBadge or if there is a preferred way, please let me know.

Thanks


To answer your 1) question: you can use Bitmap.createScaledBitmap to scale a bitmap to a given size.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号