如何在Android线性布局上获得阴影?

Mar*_*tin 22 layout android shadow

可能重复:
如何在android中将阴影设置为View?

在我的Android应用程序中,我需要一个带圆角的布局,背景应该有一些透明度.为此,我使用这个xml,它工作正常:

customshape.xml:

<shape android:shape="rectangle"> 
    <gradient android:startColor="#E2FFFFFF" android:endColor="#E2D0E3E5" android:angle="270"/> 
    <corners android:radius="10dp" /> 
</shape>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

我还需要在布局的右侧和底部有一个小阴影.我找不到办法做到这一点.我已经看到了一个黑客,你把另一个布局放在后面,使它看起来像一个阴影,但这对我不起作用,因为我的布局有透明度,所以看起来不会很好.如何在不使用图像作为布局背景的情况下在布局上获得漂亮的阴影效果?

jav*_*d76 64

我知道这已经晚了,但我正在阅读这个问题/答案组合,虽然是一种不需要图像的替代方法.我把一篇帖子放在我的博客上解释.我认为未来的访问者可以在这里获得这两个答案.

http://web.archive.org/web/20120520203231/http://www.anotherandroidblog.com/2011/06/29/drop-shadow-linearlayout/

  • 请编辑您的答案并添加解决方案,这样即使您的博客有一天会离线,我们仍然可以享受它. (13认同)

Mat*_*man 8

据我所知,没有办法将阴影应用于View对象.我建议你看看九个补丁,我用它们制作了一个阴影.

http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch

(另请参阅此答案Custom ImageView with drop shadow)