Android的ImageButton當(dāng)顯示Drawable圖片時(shí)就不顯示文字
更新時(shí)間:2013年06月02日 16:21:18 作者:
Android提供的ImageButton當(dāng)顯示Drawable圖片時(shí)就不會(huì)再顯示文字了,下面與大家分享下3種解決方法,不會(huì)的朋友可以了解下哈
很多人對 Android提供的ImageButton有個(gè)疑問,當(dāng)顯示Drawable圖片時(shí)就不會(huì)再顯示文字了,其實(shí)解決的方法有三種:
第一種:就是圖片中就寫入文字,但是這樣解決會(huì)增加程序體積,同時(shí)硬編碼方式會(huì)影響多國語言的發(fā)布。
第二種:解決方法很簡單,通過分析可以看到ImageButton的 layout,我們可以直接直接繼承,添加一個(gè)TextView,對齊方式為右側(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,對齊方式為右側(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中如何利用AIDL機(jī)制調(diào)用遠(yuǎn)程服務(wù)
這篇文章主要介紹了Android中如何利用AIDL機(jī)制調(diào)用遠(yuǎn)程服務(wù)的相關(guān)資料,需要的朋友可以參考下2016-03-03
Android TextView使用SpannableString設(shè)置復(fù)合文本的方法詳解
這篇文章主要介紹了Android TextView使用SpannableString設(shè)置復(fù)合文本的方法,結(jié)合實(shí)例形式詳細(xì)分析了Android中SpannableString類的功能及相關(guān)用法,需要的朋友可以參考下2016-08-08
Android利用Intent.ACTION_SEND進(jìn)行分享
這篇文章主要介紹了Android利用Intent.ACTION_SEND進(jìn)行分享,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-05-05
android自定義View實(shí)現(xiàn)簡單五子棋游戲
這篇文章主要為大家詳細(xì)介紹了android自定義View實(shí)現(xiàn)簡單五子棋游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05
android事件分發(fā)機(jī)制的實(shí)現(xiàn)原理
本篇文章主要介紹了android事件分發(fā)機(jī)制的實(shí)現(xiàn)原理,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-09-09
Android Studio3.6新特性之視圖綁定ViewBinding使用指南
這篇文章主要介紹了Android Studio3.6新特性之視圖綁定ViewBinding使用指南,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03
Android自定義View實(shí)現(xiàn)數(shù)字密碼鎖
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)數(shù)字密碼鎖,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-06-06

