一,第一步xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/time_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="111111"
android:textSize="15sp" />
</LinearLayout>
二,第二步activity
time_text = (TextView) findViewById(R.id.time_text)
int image_new = R.mipmap.icon_new
int image_official = R.mipmap.icon_official
String html = "还剩还剩还剩还剩还剩还剩 还剩还剩还剩还剩还剩还剩还剩还剩还剩还剩还剩还剩<img src='%1$s'> <img src='%2$s'>"
html = String.format(html, image_new, image_official)
time_text.setText(Html.fromHtml(html, new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
int id = Integer.valueOf(source)
Drawable drawable = getResources().getDrawable(id)
//手动生成Drawable的时候 ,一般都要setBounds一下, 不然有时候会报错,记住就行了,
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight())
return drawable
}
}, null))