Xml文件中設(shè)置相信大家都已經(jīng)非常的熟悉了.
<TextView
android:id="@+id/register_zone"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:drawableRight="@mipmap/lbs_arrow_down"/>
使用代碼設(shè)置DrawableLeft,Right
第一種方案
Drawable drawable = SwmUIUtils.getDrawable(imgs[position]);
// 確定drawable的位置
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
// setCompoundDrawables 畫的drawable的寬高是按drawable.setBound()設(shè)置的寬高,
// 所以才有The Drawables must already have had setBounds(Rect) called.
// 使用之前必須使用Drawable.setBounds設(shè)置Drawable的長寬。`
mTaskProgress.setCompoundDrawables(null, null, drawable, null);
第二種方案
setCompoundDrawablesWithIntrinsicBounds(null, null, UIUtils.getDrawable(R.mipmap.up_arrow), null);
setCompoundDrawablesWithIntrinsicBounds是畫的drawable的寬高是按drawable固定的寬高西采,
所以才有The Drawables' bounds will be set to their intrinsic bounds.
即通過getIntrinsicWidth()與getIntrinsicHeight()獲得萄窜,