2014-01-15 119 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

相关问题