2015-06-06 61 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

很高興幫助你... –