http://blog.csdn.net/csdn_ask/article/details/8640994
原问题来自于CSDN问答频道,更多解决方案见:
原问题描述:
xml中的textView:
- <TextView
- android:id="@+id/bookTitle"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:drawableLeft="@drawable/checkmark"
- android:gravity="center_vertical"
- android:textStyle="bold"
- android:textSize="24dip"
- android:maxLines="1"
- android:ellipsize="end"/>
解决方案:
- public void setCompoundDrawables (Drawable left, Drawable top, Drawable right, Drawable bottom);
1.在XML中使用
- android:drawableLeft="@drawable/icon"
- Drawable drawable= getResources().getDrawable(R.drawable.drawable);
- /// 这一步必须要做,否则不会显示.
- drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
- myTextview.setCompoundDrawables(drawable,null,null,null);
-
- public void setCompoundDrawablesWithIntrinsicBounds (Drawable left,
- Drawable top, Drawable right, Drawable bottom)