Android uses TextView to implement picture plus text description

Source: Internet
Author: User

Background: List of contacts, each cell displays the Avatar + name, and the avatar shows a circle

Scenario One: ImageView + TextView

Scenario Two: Use only the TextView + Drawableleft property

<textview        android:id= "@+id/textview"        android:layout_width= "match_parent"        android:layout_height= "Wrap_content"        android:padding= "@dimen/padding_30"        android:drawableleft= "@drawable/icon_person_default "        android:drawablepadding=" @dimen/padding_20 "        android:text=" @string/setting_direimage_person_name_ Default "        android:textcolor=" #464646 "        android:textsize=" 24sp "        android:gravity=" center_vertical "        android:background= "#ffffff"/>

So the question is, how do you show the round head?

If it's a scenario one, it's easy to add a background background with shape

Here is the main idea of scenario two:

TextView has a method called Setcompounddrawables (drawable left,drawable top,drawable right,drawable bottom), which is described in detail in the API, If I want to add an image to the left of the text, just construct (drawable left,null,null,null)

So when I construct this left picture, can I customize a drawable and realize rounded corners? By Baidu Google, it is possible

I post a custom drawable code that is no longer elaborated here

52967200

Here I use the following directly in adapter:

New circledrawable ((Contacts.getbitmap ()));//Please do not care what the Contacts.getbitmap () is, Here is a bitmap can drawable.setbounds (0,0,146,146),//size according to your needs holder.textView.setCompoundDrawables ( drawable,null,null,null);           

If not enough please point out, thank you!

Android uses TextView to implement picture plus text description

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.