如何获得阴影在Android线性布局? [英] How to get shadow on android linear layout?
问题描述
可能重复:
如何设置阴影在Android的视图?
在我的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?
推荐答案
据我知道有没有办法应用阴影到查看
对象。我建议你看一看九补丁,我已经用他们做了一层阴影。
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.
<一个href="http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch">http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
(另见这个答案<一个href="http://stackoverflow.com/questions/3693234/custom-imageview-with-drop-shadow/4405209#4405209">Custom ImageView的有阴影)
这篇关于如何获得阴影在Android线性布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!