在TextView中添加图片属性
在代碼中的實(shí)現(xiàn):
Drawable drawable = getResources().getDrawable(p_w_picpathlist.get(position));
// / 這一步必須要做,否則不會顯示.
drawable.setBounds(0, 0, drawable.getMinimumWidth(),
drawable.getMinimumHeight());
//四個參數(shù),分別對應(yīng)4個位置
textView.setCompoundDrawables(drawable, null, null, null);
當(dāng)然,給TextView 添加圖片還有一種簡單的方式, 我們只要在xml里添加一個樣式即可.
android:drawableBottom 在text的下方添加一個Drawable圖片
android:drawableLeft 在text的左邊添加一個Drawable圖片
android:drawableTop 在text的上方添加一個Drawable圖片
android:drawableRight 在text的右邊添加一個Drawable圖片
如果要控制圖片和Text的距離, 可以用
android:drawablePadding
轉(zhuǎn)載于:https://blog.51cto.com/freemanl/1324120
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的在TextView中添加图片属性的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Yii rabc角色权限管理文章推荐
- 下一篇: LeetCode:Longest Con