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