TextView中图文混排

        TextView mSubjectDetailView = (TextView) findViewById(R.id.TextView); 
       
        CharSequence text = "如图所示★,dsfdsfdddd,如果fdsfs★东东"; 
        SpannableStringBuilder builder = new SpannableStringBuilder(text); 
        String rexgString = "★"; 
        Pattern pattern = Pattern.compile(rexgString); 
        Matcher matcher = pattern.matcher(text); 
         
        while (matcher.find()) {
         Drawable drawable = this.getResources().getDrawable(R.drawable.f_static_000);   
            drawable.setBounds(0, 0, 14, 14);//这里设置图片的大小   
            ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);            
            builder.setSpan( imageSpan, matcher.start(), matcher 
                            .end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
        } 
         
        mSubjectDetailView.setText(builder); 

你可能感兴趣的:(TextView中图文混排)