Dynamically set the drawableLeft icon for the TextView control, and set the spacing, textviewdrawable

Source: Internet
Author: User

Dynamically set the drawableLeft icon for the TextView control, and set the spacing, textviewdrawable

:



Important attributes:

TextView. setCompoundDrawablePadding (4); // you can specify the spacing between the image and text.

TextView. setPadding (-5, 0, 0, 0); // set the overall padding

Private TextView addDesc (String [] MemDescs, int I) {String MemDesc = MemDescs [I]; TextView textView = new TextView (this); textView. setText (MemDesc); // Add the image Drawable drawable = getResources () on the left (). getDrawable (R. drawable. gray_circle); drawable. setBounds (0, 0, drawable. getMinimumWidth (), drawable. getMinimumHeight (); textView. setCompoundDrawables (drawable, null, null); textView. setTextColor (getResources (). getColor (R. color. gray_textcolor_shen); textView. setCompoundDrawablePadding (4); // set the spacing between the image and text textView. setPadding (-5, 0, 0, 0); return textView ;}


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.