【问题标题】:Transparent image background is showing on ImageButtonImageButton 上显示透明图像背景
【发布时间】:2015-08-14 21:18:19
【问题描述】:

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

这是我的 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"
    />

【问题讨论】:

  • 请发布您的 xml
  • 您的图片是否保存在 .png 扩展名中?
  • @Aakash 我在我的 xml 中为 ImageButton 编辑
  • @mubeen 是的,它是一个 .png 文件

标签: android android-layout imagebutton android-imagebutton


【解决方案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"
    />

【讨论】:

    【解决方案2】:

    图像周围的透明区域,如果它是图像的一部分,会影响图像的实际宽度和高度,想象一下图像的透明部分是否是彩色区域而不是透明区域,您可以查看如何它将成为您图像的一部分,即使它是透明的,它占用的区域也会影响图像的高度和宽度

    【讨论】:

    • 我认为可能是这种情况,但是如何制作一个仅是彩色区域本身的图像按钮?
    • 在您的图形软件中选择只是没有透明区域的图像复制并粘贴为没有透明区域的新图像,应该可以工作
    • 我们知道您的图像周围有一个透明区域,但您的图形软件只能看到图像的宽度和高度,它无法识别图像是什么或您试图实现的目标它只是识别该区域整个图像占据了
    【解决方案3】:

    "wrap_content" 属性只是将你的按钮的高度设置为你的图像的高度。 如果您只想保留图像的彩色部分,只需调整它的大小! ;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 2012-10-01
      • 1970-01-01
      • 2010-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多