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