在文本视图中添加图像有效。将图像高度和宽度更改为文本视图文本高度不起作用。(原图“红圈”为:32px x 32px)
输出如下所示:
测试img http://img850.imageshack.us/img850/9500/m1f.png
XML:
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp" />
代码:
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView)findViewById(R.id.textView);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
super.onWindowFocusChanged(hasFocus);
String getText = getResources().getString(R.string.getText);
textView.setText(getText);
SpannableStringBuilder ssb = new SpannableStringBuilder(getText);
Bitmap redcircle= BitmapFactory.decodeResource( getResources(), R.drawable.redcircle );
Bitmap resizedbitmap = Bitmap.createScaledBitmap(redcircle, (int)textView.getMeasuredHeight(), (int)textView.getMeasuredHeight(), true);
ssb.setSpan( new ImageSpan( resizedbitmap ), 3, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE );
textView.setText( ssb, BufferType.SPANNABLE );
}
编辑:
我想要,图像高度和宽度等于文本视图文本高度。例如像这样: