Android drawable attributes

Source: Internet
Author: User

 

The android control textview can be set to display a drawable image );

 

The simplest way is to set the property drawableleft in XML;

 

However, if you want to change images dynamically, you can refer to the following method:

 

. Setcompounddrawables (left, top, right, bottom );

(Note: Remember to set the drawable to setbrounds)

 

To:

Http://wangshuaibo.iteye.com/blog/952279

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~

 

You can use the following methods to manually set the relative position of text and image:
Setcompounddrawables (left, top, right, bottom );
SetcompounddrawableswithIntrinsicbounds (left, top, right, bottom)
Set the left, top, right, and bottom positions of the drawable text.
(Both textview and button can be used)
But there are some differences between the two:

The width and height of the drawable drawn by setcompounddrawables are based on drawable. the drawables must already have had setbounds (rect) called. it means that drawable must be used before use. setbounds sets the length and width of drawable.
While setcompounddrawableswithIntrinsicbounds indicates that the width and height of the drawn drawable are fixed by drawable, which is obtained through getintrinsicwidth () and getintrinsicheight, therefore, the drawables 'bounds will be set to their intrinsic bounds. this sentence!

 

Http://blog.sina.com.cn/s/blog_5da93c8f0100vr93.html

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.