可能重复:
how to set shadow to a View in android?
在我的Android应用程序中,我需要一个圆角布局,背景应该有一些透明度。为此,我使用了这个xml,它运行得很好:
customshape.xml:
<shape android:shape="rectangle">
<gradient android:startColor="#E2FFFFFF" android:endColor="#E2D0E3E5" android:angle="270"/>
<corners android:radius="10dp" />
</shape>
style.xml:
<style name="LinearLayoutRoundCorners">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">@drawable/customshape</item>
</style>
我还需要一个小阴影的右侧和底部的布局。我找不到办法做这件事。我看到了一个黑客,你在后面放了另一个布局,让它看起来像个阴影,但这对我不起作用,因为我的布局是透明的,所以看起来不太好。如果不使用图像作为布局的背景,我如何才能在布局上得到一个漂亮的阴影?
发布于 2011-04-02 07:21:23
据我所知,无法将阴影应用于View
对象。我建议你看一下九个补丁,我用它们做了一个阴影。
http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
发布于 2011-06-29 01:24:55
我知道这已经太晚了,但我读了这个问题/答案的组合,还有一种不需要图像的替代方法。我在博客上写了一篇文章解释。我认为这将有助于未来的游客在这里有这两个答案方便。
https://stackoverflow.com/questions/5523936
复制相似问题