如何在Android线性布局上获得阴影? [英] How to get shadow on android linear layout?
问题描述
可能重复:
如何设置阴影到Android中的View?
在我的Android应用程序中,我需要一个带有圆角的布局,背景应该有一些透明度。为此,我使用这个xml,它工作正常:
In my Android app I need a layout with round corners and the background should have some transparency. For this I'm using this xml, it works fine:
customshape.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.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>
我还需要一个小的阴影在右侧和底部的布局。我找不到办法做到这一点。我看到一个黑客,你把另一个布局放在后面,使它看起来像一个阴影,但这对我来说不会有效,因为我的布局有透明度,所以看起来不是很好。如何在布局上获得一个漂亮的阴影,而不使用图像作为布局的背景?
I also need a small shadow to the right and bottom of the layout. I can not find a way to do this. I've seen a hack where you put another layout behind to make it look like a shadow but that will not work for me as my layout have transparency, so that will not look very good. How can I get a nice looking shadow on my layout without using an image as background of the layout?
推荐答案
就我而言知道没有办法将影子应用于 View
对象。我建议你看看九个补丁,我已经用它们来做一个阴影。
As far as I know there is no way to apply a shadow to a View
object. I suggest you take a look at nine patches, I have used them to make a shadow.
http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
(另见此答案带有阴影的自定义ImageView )
这篇关于如何在Android线性布局上获得阴影?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!