简体   繁体   English

如何为ImageButton添加高程?

[英]How to add elevation to ImageButton?

I added an ImageButton and set it background to imagedrawable but when i add elevation to it I get a rectangular shadow. 我添加了一个ImageButton并将其背景设置为imagedrawable,但是当我向其添加高程时,我得到一个矩形阴影。

here is my button: 这是我的按钮:

<ImageButton
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:background="@drawable/ic_bookmark_red"
        android:layout_gravity="left"
        android:id="@+id/bm"
        android:elevation="6dp"/>

Here is the drawable i used : 这是我使用的可绘制对象:

在此处输入图片说明

I think you have to draw your drawable as a svg symbol. 我认为您必须将可绘制对象绘制为svg符号。

Is your drawable a .jpg? 您的图片是.jpg吗? JPG does not support transparent backgrounds and sure, the shadow will be rectangular, because a JPG is always rectangular. JPG不支持透明背景,请确保阴影为矩形,因为JPG始终为矩形。

It may will work with a PNG file which has a transparent background (take care, that the background is transparent, not white), but i did not test it. 它可能会与具有透明背景的PNG文件一起使用(请注意,背景是透明的,而不是白色),但是我没有对其进行测试。

But with a svg drawable it will work! 但是使用svg drawable可以正常工作! Maybe the symbol library from Android Studio has a symbol that fits you needs. 也许来自Android Studio的符号库具有适合您需要的符号。

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

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