android setCompoundDrawables和setCompoundDrawablesWithIntrinsicBounds區別


手工設置文本與圖片相對位置時,常用到如下方法:

setCompoundDrawables(left, top, right, bottom)


setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom)


意思是設置Drawable顯示在text的左、上、右、下位置。


但是兩者有些區別:
setCompoundDrawables 畫的drawable的寬高是按drawable.setBound()設置的寬高,
所以才有The Drawables must already have had setBounds(Rect) called.

使用之前必須使用Drawable.setBounds設置Drawable的長寬。


setCompoundDrawablesWithIntrinsicBounds是畫的drawable的寬高是按drawable固定的寬高,
所以才有The Drawables' bounds will be set to their intrinsic bounds.

即通過getIntrinsicWidth()與getIntrinsicHeight()獲得,

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM