2015-06-06 58 views
1

朋友你好我想我绘制的图像来结束我的textview不灵drawableEnd TextView的属性,所以我把我的布局如下移动机器人

xml文件

<TextView 
      android:id="@+id/text_four" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/text_two" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" 
      android:text="Go ahead and get to the area you want then" 
      android:drawableEnd="@drawable/alogo_small" 
      android:textColor="@android:color/black" 
      android:textSize="@dimen/text_15" 
      android:visibility="visible" /> 

当我在上面运行代码是我的鞋样输出下面

enter image description here

我想我drawab后then所以任何想法我怎么能解决这个问题?你的所有建议都明显

编辑

SpannableString ss = new SpannableString("Go ahead and get to the area you want then"); 
    Drawable d = getResources().getDrawable(R.drawable.alogo_small); 
    d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); 
    ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE); 
    ss.setSpan(span, ss.length(), ss.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
    mTextViewEmailTwo.setText(ss); 

当我运行上面的代码给我输出像下面

enter image description here

回答

2

尝试使用Html.ImageGetter:

Html.ImageGetter getter = new Html.ImageGetter(){ 
    public Drawable getDrawable(String source){ // source is the resource name 
    Drawable d = null; 
    Integer id = new Integer(0); 
    id = getApplicationContext().getResources().getIdentifier(source, "drawable",getPackageName()); 

    d = getApplicationContext().getResources().getDrawable(id); 

    if (d != null) 
     d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); 
     return d; 
    } 
}; 

String imgString = "Go ahead and get to the area you want then " + " <img src=\"alogo_small\"/>"; 
mTextViewEmailTwo.setText(Html.fromHtml(imgString, getter, null)); 
+0

Haresh Chhelana:“is”的价值是多少, 'index','strLength'? –

+1

Haresh Chhelana ::雅完美的作品 –

+0

很高兴帮助你... –