2013-01-04 178 views
1

嗨,我想創建像這樣的圖像按鈕http://imgur.com/sshdf在這個URL我如何創建按鈕像這樣?半圖像半文字?請幫助我,我想創建完全相同按鈕如何在按鈕中添加圖像?圖像與文字

  <Button android:id="@+id/MyAccountMiniStatement" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_height="25dip" 
       android:layout_width="fill_parent" 
       android:layout_marginRight="10dip" 
       android:layout_marginLeft="10dip" 


      android:background="@drawable/curvedplanebutton" 
      android:textColor="@drawable/button_text_color" 
      android:layout_marginTop="10dip" 
      android:text="Mini Statement"/> 

回答

0

這個屬性添加到按鈕android:drawableLeft="@drawable/ic_launcher"

這樣的事情,

 <Button android:id="@+id/MyAccountMiniStatement" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_height="25dip" 
     android:layout_width="fill_parent" 
     android:layout_marginRight="10dip" 
     android:layout_marginLeft="10dip" 
     android:drawableLeft="@drawable/ic_launcher" 
     android:background="@drawable/curvedplanebutton" 
     android:textColor="@drawable/button_text_color" 
     android:layout_marginTop="10dip" 
     android:text="Mini Statement"/> 

通過提供可繪製左側時,圖標將被放置到文本的左側,還可以使用背景屬性爲整個按鈕提供白色背景。

+0

日Thnx是幫我 –

+0

歡迎我的朋友。 –

0

你爲什麼不使用ImageBUtton,我認爲這將是對你有好處

<ImageButton 
    android:id="@+id/ImageButton01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/album_icon" 
    android:background="@drawable/round_button" /> 
0

解決方案是使用CompoundDrawable

一些屬性的按鈕和TextView的:

1. android:drawableLeft 
2. android:drawableTop 
3. android:drawableRight 
4. android:drawableBottom 

而且是用android:drawablePadding到你的文字和圖像之間給填充。

0

使用文本視圖和文本和android:drawableTop="@drawable/ic_launcher"在textview中的圖像。

所以使用這個後,你可以看到你的textview也包含圖像。

請嘗試下面的代碼而不是您的按鈕代碼。

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:drawableTop="@drawable/ic_launcher" 
    android:gravity="center" 
    android:text="Hello" /> 

此外,您可以添加drawable到任何一邊。 頂部,底部,右側,左側。

android:drawableBottom="@drawable/ic_launcher" 
    android:drawableTop="@drawable/ic_launcher" 
    android:drawableRight="@drawable/ic_launcher" 
    android:drawableLeft="@drawable/ic_launcher" 

更多細節Follow This Link