Android的ImageButton不能顯示文字

來源:互聯網
上載者:User
 

很多人對 Android提供的ImageButton有個疑問,當顯示Drawable圖片時就不會再顯示文字了,其實解決的方法有三種:

 

第一種:就是圖片中就寫入文字,但是這樣解決會增加程式體積,同時寫入程式碼方式會影響多國語言的發布。

 

第二種:解決方案很簡單,通過分析可以看到ImageButton的 layout,我們可以直接直接繼承,添加一個TextView,對齊為右側即可實現ImageButton支援文字右側顯示。

 

第三種:更簡潔效率的方法:使用Button ,然後設定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>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.