简体   繁体   English

Android Studio 和 PNG 矢量图像

[英]Android Studio and PNG vector images

Creating vector images in Photoshop (for transparent backgrounds).在 Photoshop 中创建矢量图像(用于透明背景)。 When I add them as the image source for my ImageButtons, and run the app, the image displays with a white background.当我将它们添加为我的 ImageButton 的图像源并运行该应用程序时,图像显示为白色背景。

Can't find any useful info on why the images are not coming out transparent through the app.无法找到有关为什么图像无法通过应用程序透明显示的任何有用信息。

Are there some additional steps/coding required to make vector images work properly?是否需要一些额外的步骤/编码才能使矢量图像正常工作? I can't see why.我不明白为什么。

Example code, as requested:示例代码,按要求:

<ImageButton
    android:id="@+id/btnGameUp"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:src="@drawable/arrowright"
    android:adjustViewBounds="false"
    android:clickable="true"
    android:cropToPadding="false"
    android:padding="0dp"
    android:scaleType="fitXY"
    android:layout_marginLeft="270dp"
    android:layout_marginTop="260dp" />

No one came to help us, but we managed to find the solution on our own after hours of crying and holding each other for comfort.没有人来帮助我们,但经过几个小时的哭泣和互相拥抱以求安慰后,我们设法自己找到了解决办法。

In the layout xml file, you need to add the following line to each vector object:在layout xml文件中,需要在每个vector对象中添加以下行:

android:background="@android:color/transparent"

That's it!就是这样! Tested and working perfectly.经过测试并完美运行。 Hope this helps someone.希望这可以帮助某人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM