ImageView并不总是透明的,而是显示空白区域

时间:2016-02-01 20:03:06

标签: java android xml imagebutton

我对ImageButton

有疑问

ImageView手机上有空白区域,而另一个手机没有白色空间。那是为什么?

我需要在所有手机上使用透明ImageView

<FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="@dimen/large"
    android:layout_weight="0.66"
    android:paddingTop="6dp"
    android:paddingLeft="2dp"
    android:paddingRight="2dp">

    <ImageButton
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/stuUP"
        android:layout_weight="1.1"
        android:onClick="BtnstuUP"
        android:baselineAlignBottom="false"
        android:src="@mipmap/btup"
        android:scaleType="fitCenter"
        android:background="@android:color/transparent" />
</FrameLayout>

你知道问题出在哪里吗?以下是两个屏幕截图(Display 1Display 2)以供进一步说明。

显示1小米Mi3 - 坏视图

显示2 Acer Z520 - Good View

1 个答案:

答案 0 :(得分:0)

如果图像是png格式,您可以使用imageView.setColorFilter(“#00000000”)方法设置颜色,请注意,这将使其完全透明。前两个00是不透明度,而剩下的六个是主色。如果图像是单色,则此方法有效。我是说同样的颜色。否则,我建议你使用像photoshop,inkscape,sketch等图像编辑器,使图像在使用前透明。谢谢希望这能回答你的问题。