45
A
回答
91
發現以下的,似乎做的工作:
public class TestActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textView = (TextView) findViewById(R.id.textview);
SpannableString ss = new SpannableString("abc");
Drawable d = getResources().getDrawable(R.drawable.icon32);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
ss.setSpan(span, 0, 3, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
textView.setText(ss);
}
17
SpannableString + ImageSpan不要在Android的API 21 & 22工作(我在Android Studio中1.2測試。 1.1模擬器),但如果你這樣做:
TextView textView = (TextView) findViewById(R.id.textview);
textView.setTransformationMethod(null);
...
textView.setText(ss);
SpannableString + ImageSpan將工作。
'd.setBounds(0,0,d.getIntrinsicWidth(),d.getIntrinsicHeight());'是可繪製的關鍵不具有固有界限。 – 2015-10-27 21:17:35
getDrawable函數折舊請更新您的答案 – 2017-03-17 10:23:22
如果我想調整ImageSpan在可擴展的 .. 字符串中的位置?例子我想給底部的Imagpan一個10dp的餘量。 – Khay 2017-05-04 07:24:14