如何在 Android 中的线性布局周围显示阴影? [英] How to show shadow around the linearlayout in Android?
问题描述
如何为我的线性布局显示阴影.我想要白色圆形背景,线性布局周围有阴影.到目前为止,我已经这样做了.
How can I show shadow for my linear layout. I want white colored rounded background with shadow around the linearlayout. I have done this so far.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@xml/rounded_rect_shape"
android:orientation="vertical"
android:padding="10dp">
<-- My buttons, textviews, Imageviews go here -->
</LinearLayout>
和xml目录下的rounded_rect_shape.xml
And rounded_rect_shape.xml under xml directory
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#ffffff" />
<corners
android:bottomLeftRadius="3dp"
android:bottomRightRadius="3dp"
android:topLeftRadius="3dp"
android:topRightRadius="3dp" />
</shape>
推荐答案
Android 中没有这个属性,用来显示阴影.但可能的方法是:
There is no such attribute in Android, to show a shadow. But possible ways to do it are:
添加一个带有灰色的普通 LinearLayout,在其上添加您的实际布局,底部和右侧的边距等于 1 或 2 dp
Add a plain LinearLayout with grey color, over which add your actual layout, with margin at bottom and right equal to 1 or 2 dp
有一个带有阴影的 9-patch 图像,并将其设置为线性布局的背景
Have a 9-patch image with a shadow and set it as the background to your Linear layout
这篇关于如何在 Android 中的线性布局周围显示阴影?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!