2011-11-01 50 views
0

其實我有一些文本的TextView。我需要插入一個圖像洞察這個文本。請建議最好的方法來做到這一點。應該支持不同的顯示尺寸。Android。如何在文本中插入圖像

+0

可能重複的http:// stackoverflow.com/questions/7913987/how-to-insert-imageview-at-the-end-of-multiline-textview – Vladimir

回答

1

你在任上/下/左/右側TextView的內部談論到顯示圖像,如果是的話:

<TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Hello World, DemoExampleActivity!" 
     android:drawableLeft="@drawable/icon" 
     android:drawableRight="@drawable/icon" 
     android:drawablePadding="10dip"/> 

輸出:

enter image description here

0

可以設置作爲背景的圖像TextView這樣的背景:

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Text to be displayed" 
    android:background ="@drawable/your_image" 
    /> 

祝你好運, Arkde

0

如果想通過XML

做添加此屬性TextView元素

​​

如果在運行時編程

TextView tv = (TextView)findViewById(R.id.textView); 
    tv.setBackgroundDrawable(drawable); 

      or 

    tv..setBackgroundResource(resid);