设置TextView的drawable
代码设置: setCompoundDrawables()
Drawable drawable = getResources().getDrawable(image);
// 这一步必须要做,否则不会显示.
int px = DensityUtils.dip2px(5);
//这里也别说明一下,是要动态改变显示图标的大小(在xml里是没有api改变的)
drawable.setBounds(0, 0, (drawable.getMinimumWidth()*3/2),drawable.getMinimumHeight()*3/2);
this.textTitle.setCompoundDrawablePadding(px);
this.textTitle.setCompoundDrawables(null, null, drawable, null);
xml设置 drawableRight
<TextView
android:id="@+id/favort"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="18dp"
android:drawablePadding="6dp"
android:drawableRight="@mipmap/ico_dianzan"
android:gravity="center_vertical"
android:text="0"
android:textSize="12sp"/>
以上,git地址: https://github.com/xzkuse/StudentQuestionnaire.git