2015-08-14 56 views
0

我有一个图像(图片1),它周围有一个透明区域,延伸到图像本身的上方和下方(图片2)。当我在xml中添加这个图像作为ImageButton并使用wrap_content时,图片2中的透明区域正在成为按钮的一部分,而不仅仅是按钮本身(图片1)。图3是结果。有谁知道如何解决这个问题?在ImageButton上显示透明图像背景

Button

Button

enter image description here

这里是我的XML:

<ImageButton 
    android:id="@+id/resume_button" 
    android:src="@drawable/disabled_resume_button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/new_checklist" 
    android:layout_centerHorizontal="true" 
    /> 
+0

发表您的XML请 – Aakash

+0

是你的图像保存为.png扩展名? – mubeen

+0

@Aakash我在ImageButton中编辑了我的xml – Brejuro

回答

0

图像周围的透明区域,如果图像的一部分对图像的实际宽度和高度有贡献,请想象图像的透明部分是彩色区域而不是透明区域,而您可以visulise怎么会是你的形象的一部分,尽管它的透明它占用了有助于图像

+0

我认为这可能是这种情况,但是我该如何制作一个只是彩色区域本身的图像按钮? – Brejuro

+0

在您的图形软件中选择JUST图像没有透明区域复制和粘贴为一个新的图像没有周围的透明区域,这应该工作 – Lynnywinny

+0

我们知道你的图像周围有一个透明的区域,但你的图形软件只看到宽度和图像的高度,它能够识别图像是什么或者你试图达到什么目的,它只是识别整个图像所占的区域 – Lynnywinny

-1

“WRAP_CONTENT” 属性刚刚成立YOUT按钮的高度,以YOUT图像的高度。 如果您只想保留图像的彩色部分,只需调整它的大小! ;)

1

的高度和宽度的区域这样做:

<ImageButton 
    android:id="@+id/resume_button" 
    android:background="@drawable/disabled_resume_button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/new_checklist" 
    android:layout_centerHorizontal="true" 
    />