Android在TextView中设置图片显示问题

设置左侧带图片的TextView,可以通过android:drawableLeft属性进行设置:

<TextView
    android:id="@+id/bottom_info"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="@dimen/dp_26"
    android:drawableLeft="@drawable/warn_icon"
    android:drawablePadding="@dimen/dp_7"/>

但是有时候会存在图片大小不合适或者图片显示不完整等原因,可以在java代码中对图片进行如下设置:

Drawable drawable = ContextCompat.getDrawable(LifeOrderDetailActivity.this, R.drawable.warn_icon);
drawable.setBounds(0,0,20,20);
bottom_info.setCompoundDrawables(drawable,null,null,null);

猜你喜欢

转载自blog.csdn.net/u014330846/article/details/80176130