Android的ImageButton當(dāng)顯示Drawable圖片時(shí)就不顯示文字
更新時(shí)間:2013年06月02日 16:21:18 作者:
Android提供的ImageButton當(dāng)顯示Drawable圖片時(shí)就不會(huì)再顯示文字了,下面與大家分享下3種解決方法,不會(huì)的朋友可以了解下哈
很多人對(duì) Android提供的ImageButton有個(gè)疑問,當(dāng)顯示Drawable圖片時(shí)就不會(huì)再顯示文字了,其實(shí)解決的方法有三種:
第一種:就是圖片中就寫入文字,但是這樣解決會(huì)增加程序體積,同時(shí)硬編碼方式會(huì)影響多國語言的發(fā)布。
第二種:解決方法很簡單,通過分析可以看到ImageButton的 layout,我們可以直接直接繼承,添加一個(gè)TextView,對(duì)齊方式為右側(cè)即可實(shí)現(xiàn)ImageButton支持文字右側(cè)顯示。
第三種:更簡潔效率的方法:使用Button ,然后設(shè)定Button 的 android:drawableLeft 等屬性即可。示例:
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/icon"
android:text="按鈕"
/>
第四種:用布局多封一層
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/bt">
<ImageView
android:id="@+id/ib"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ringlove"
android:background="#00000000"
/>
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cs"
android:paddingLeft="20px"
/>
</LinearLayout>
第一種:就是圖片中就寫入文字,但是這樣解決會(huì)增加程序體積,同時(shí)硬編碼方式會(huì)影響多國語言的發(fā)布。
第二種:解決方法很簡單,通過分析可以看到ImageButton的 layout,我們可以直接直接繼承,添加一個(gè)TextView,對(duì)齊方式為右側(cè)即可實(shí)現(xiàn)ImageButton支持文字右側(cè)顯示。
第三種:更簡潔效率的方法:使用Button ,然后設(shè)定Button 的 android:drawableLeft 等屬性即可。示例:
復(fù)制代碼 代碼如下:
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/icon"
android:text="按鈕"
/>
第四種:用布局多封一層
復(fù)制代碼 代碼如下:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/bt">
<ImageView
android:id="@+id/ib"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ringlove"
android:background="#00000000"
/>
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cs"
android:paddingLeft="20px"
/>
</LinearLayout>
您可能感興趣的文章:
- Android編程之canvas繪制各種圖形(點(diǎn),直線,弧,圓,橢圓,文字,矩形,多邊形,曲線,圓角矩形)
- Android ImageView繪制圓角效果
- Android Bitmap和Drawable相互轉(zhuǎn)換的簡單代碼
- android中圖形圖像處理之drawable用法分析
- 詳解Android中Drawable方法
- 關(guān)于Android中drawable必知的一些規(guī)則
- Android Drawable及其相關(guān)類的使用
- 玩轉(zhuǎn)Android之Drawable的使用
- Android Drawable必備知識(shí)小結(jié)
- Android自定義Drawable實(shí)現(xiàn)圓形和圓角
- Android開發(fā)使用Drawable繪制圓角與圓形圖案功能示例
相關(guān)文章
Android開發(fā)之RadioGroup的簡單使用與監(jiān)聽示例
這篇文章主要介紹了Android開發(fā)之RadioGroup的簡單使用與監(jiān)聽,結(jié)合實(shí)例形式分析了Android針對(duì)RadioGroup單選按鈕簡單實(shí)用技巧,需要的朋友可以參考下2017-07-07Android中WebView與Js交互的實(shí)現(xiàn)方法
本文給大家介紹android中webview與js交互的實(shí)現(xiàn)方法,本文介紹的非常詳細(xì),具有參考借鑒價(jià)值,感興趣的朋友一起學(xué)習(xí)2016-05-05Android如何通過手機(jī)自動(dòng)獲取短信驗(yàn)證碼
注冊(cè)帳號(hào)時(shí),經(jīng)常需要手機(jī)獲取驗(yàn)證碼,Android如何通過手機(jī)自動(dòng)獲取短信驗(yàn)證碼,下面看看小編給大家分享的一段代碼,感興趣的小伙伴們可以參考一下2016-03-03Android開發(fā)實(shí)現(xiàn)根據(jù)字母快速定位側(cè)邊欄
這篇文章主要為大家詳細(xì)介紹了Android開發(fā)實(shí)現(xiàn)根據(jù)字母快速定位側(cè)邊欄,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09Android實(shí)戰(zhàn)APP啟動(dòng)速度優(yōu)化
本篇文章給大家通過實(shí)戰(zhàn)總結(jié)了Android開發(fā)APP啟動(dòng)速度優(yōu)化的方法以及需要注意的地方,有需要的朋友可以參考下。2018-05-05Android中通過RxJava進(jìn)行響應(yīng)式程序設(shè)計(jì)的入門指南
響應(yīng)式編程在Android中的運(yùn)用是非常犀利的,比如在異常處理和調(diào)度器方面,這里我們將從生命周期等方面來講解Android中通過RxJava進(jìn)行響應(yīng)式程序設(shè)計(jì)的入門指南:2016-06-06Android文本輸入框(EditText)輸入密碼時(shí)顯示與隱藏
這篇文章主要介紹了Android文本輸入框(EditText)輸入密碼時(shí)顯示與隱藏的方法和示例,需要的朋友可以參考下2014-12-12