2014-01-15 65 views
2

我告訴你,我有以下代碼如何縮小圖像(ImageView或ImageButton)而不丟失圖像?

    <ImageButton 
         android:id="@+id/imageButton1" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:src="@drawable/happy" /> 

enter image description here

但它是太大,我需要縮小它,但是當我做了以下情況

enter image description here

    <ImageButton 
         android:id="@+id/imageButton1" 
         android:layout_width="44dp" 
         android:layout_height="41dp" 
         android:src="@drawable/happy" /> 

您可以看到圖像的某些部分丟失了,如何在沒有這種情況的情況下收縮圖像?

+0

對於這個問題,在版面 –

+0

+1中使用wieght,這個問題總是被很多人問起,也是一個令人困惑的問題,但是這個問題是可以解決的問題。 –

回答

1

要麼你需要調整原始圖像的大小,或者你可以使用一個ImageView(它具有scaleType參數)並使其可點擊,例如,

<ImageView 
    android:id="@+id/smiley_iv" 
    android:layout_width="44dp" 
    android:layout_height="41dp" 
    android:src="@drawable/happy" 
    android:scaleType="centerInside" 
    android:clickable="true" /> 

在這種情況下,你可能會想添加自己的背景選擇器(用於按鍵狀態等),很明顯,你需要添加一個onClick回調或者通過XML或編程。

+0

+1從我身邊爲你 –

+0

@Damian感謝您的回覆,幫助了我很多,但當我做你告訴我的時候,圖片會出現白色背景 – cheloncio

+0

ImageButton **是** ImageView如此downvote – pskink

相關問題