2012-05-11 82 views
0

我想創建按鈕,我有圖標和文本。這是我創建:按鈕和圖像與TXT

enter image description here

這是XML:

 <Button 
      android:id="@+id/call_button" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_marginTop="30dp" 
      android:background="@drawable/button" 
      android:layout_weight="40" 
      android:drawableLeft="@drawable/phone" 
      android:text="Call" 
      android:textColor="@color/white" 
      /> 

如何能打動我這個電話圖標更接近文本?

+0

你必須使用可繪製 - 九宮格(http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch) – adatapost

+0

檢查您的按鈕圖像的寬度。它的右邊是否有透明像素? – Tarun

回答

1

這可能會引導你進行安排,

http://developer.android.com/resources/articles/layout-tricks-efficiency.html

代碼:

<Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/home_btn_test" 
     android:drawableTop="@drawable/home_icon_test" 
     android:textColor="#FFFFFF" 
     android:id="@+id/ButtonTest" 
     android:paddingTop="32sp" 
     android:drawablePadding="-15sp" 
     android:text="this is text"></Button> 

REF從:Android: combining text & image on a Button or ImageButton

請參閱這裏:http://www.mokasocial.com/2010/04/create-a-button-with-an-image-and-text-android/

1

你有沒有嘗試提供paddingLeft屬性。

<Button android:drawableLeft="@drawable/ic_launcher" 
     android:layout_width="100dip" 
     android:paddingLeft="10dip" 
     android:layout_height="50dip" 
     android:text="hello" /> 

它幫助我將Drawable移動到Text上。

0

恐怕你不能設置該化合物可繪製的位置,但你可能會添加一些透明的像素角落找尋你的形象,應該這樣做:)

0

你可以做一件事。根據需要創建一個圖像並將其放入可繪製文件夾中。創建圖像視圖並設置該圖像,然後您可以將onclick事件設置爲該圖像。

ImageView img = (ImageView) findViewById(R.id.myImageId); 
img.setOnClickListener(new OnClickListener() { 
public void onClick(View v) { 
    // your code here 
} 
});