2012-03-14 87 views
2

我遇到了Android ImageButton的問題。 我的圖標在頂部被切斷。Android ImageButton削減圖標頂部

代碼如下:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:orientation="horizontal" 
    android:layout_marginBottom="20sp" 
    android:paddingLeft="20sp" 
    android:paddingRight="20sp" > 

    <TextView 
     android:id="@+id/registration_1_button_sex_male_title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/registration_1_male" 
     android:textColor="#fff" 
     android:textSize="15sp" 
     android:typeface="monospace" /> 

    <ImageButton 
     android:id="@+id/registration_1_button_sex_male" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@android:color/transparent" 
     android:paddingRight="20sp" 
     android:src="@drawable/icon_male_blue" /> 
</LinearLayout> 

我已經試過這我GOOGLE了,但沒有人幫助一些黑客。

+0

我也試圖在LinearLayout和ImageButton裏面添加填充,但沒有幫助,我嘗試給圖標和LinearLayout一個固定的高度,但沒有任何工作。 – kjurkovic 2012-03-14 09:42:38

+0

你可以發佈圖像? – Tony 2012-03-14 10:29:57

回答

0

嘗試增加:

android:scaleType="fitCenter" 

您的ImageButton

如果失敗嘗試下scaleType屬性的其他選項

+0

我嘗試了ScaleType的所有選項..仍然是同樣的問題 – kjurkovic 2012-03-14 09:51:34

+0

你試過移動圖標嗎?我有時在drawable-hdpi/ldpi中發現了奇怪的行爲,並且恢復爲只創建一個「drawable」文件夾。 – Tony 2012-03-14 09:53:58

+0

我試着移動它..它仍然是一樣的:\ – kjurkovic 2012-03-14 09:59:24

1

儘量保持圖像的Android:背景,而不是機器人:SRC在的ImageButton。它不是解決所有問題的解決方案,但對這類問題起到很好的作用。