[英]Android. How to insert image in text
其實我有一些文本的TextView。 我需要在此文本中插入一個圖像洞察力。 請提出最佳方法。 應該在不同的顯示尺寸上得到支持。
您是否要在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"/>
輸出:
您可以像這樣將圖像設置為TextView
的背景:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text to be displayed"
android:background ="@drawable/your_image"
/>
祝你好運,阿克德
如果想通過xml來做
將此屬性添加到TextView元素
android:background="@drawable/icon"
如果在運行時以編程方式
TextView tv = (TextView)findViewById(R.id.textView);
tv.setBackgroundDrawable(drawable);
or
tv..setBackgroundResource(resid);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.