如何在线性布局中添加阴影-Android? [英] How to add shadow to linear layout - android?

查看:146
本文介绍了如何在线性布局中添加阴影-Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的android应用程序中,我必须实现类似于下面给出的图像:

In my android application I have to implement something like the image given below :

我尝试使用阴影xmls进行线性布局,但是它似乎无法解决我想要的问题. 我正在使用的代码是:

I have tried using shadow xmls for a linear layout but it doesn't seem to work out the way i want it to be. The code that I am using is :

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
    <shape
        android:shape="rectangle">
        <solid android:color="@android:color/darker_gray" />
        <corners android:radius="5dp"/>
    </shape>
</item>
<item android:right="5dp" android:left="5dp" android:bottom="15dp">
    <shape
        android:shape="rectangle">
        <solid android:color="@android:color/white"/>
        <corners android:radius="5dp"/>
    </shape>
</item>
</layer-list>

请提出我该如何实现.

推荐答案

您可以拍摄以阴影为背景的9-patchImage,也可以将以下xml用作阴影的linearlayout背景

You can take an 9-patchImage with shadow as background or you can use the following xml as background of linearlayout for shadow

  <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Drop Shadow Stack -->
    <item>
        <shape>
            <padding android:top="1dp" android:right="1dp" android:bottom="1dp" android:left="1dp" />
            <solid android:color="#02000000" />
            <corners android:radius="8dp" />
        </shape>
    </item>
    <item>
        <shape>
            <padding android:top="1dp" android:right="1dp" android:bottom="1dp" android:left="1dp" />
            <solid android:color="#05000000" />
            <corners android:radius="7dp" />
        </shape>
    </item>
    <item>
        <shape>
            <padding android:top="1dp" android:right="1dp" android:bottom="1dp" android:left="1dp" />
            <solid android:color="#10000000" />
            <corners android:radius="6dp" />
        </shape>
    </item>
    <item>
        <shape>
            <padding android:top="1dp" android:right="1dp" android:bottom="1dp" android:left="1dp" />
            <solid android:color="#15000000" />
            <corners android:radius="5dp" />
        </shape>
    </item>
    <item>
        <shape>
            <padding android:top="1dp" android:right="1dp" android:bottom="1dp" android:left="1dp" />
            <solid android:color="#20000000" />
            <corners android:radius="4dp" />
        </shape>
    </item>
    <item>
        <shape>
            <padding android:top="1dp" android:right="1dp" android:bottom="1dp" android:left="1dp" />
            <solid android:color="#25000000" />
            <corners android:radius="3dp" />
        </shape>
    </item>
    <item>
        <shape>
            <padding android:top="1dp" android:right="1dp" android:bottom="1dp" android:left="1dp" />
            <solid android:color="#30000000" />
            <corners android:radius="3dp" />
        </shape>
    </item>

    <!-- Background -->
    <item>
    <shape>
            <solid android:color="#ffffff" />
        <corners android:radius="3dp" />
    </shape>
   </item>
</layer-list>

从不需要阴影的任何一侧去除填充物

remove padding from what ever side you don't need shadow

注意:

这不是我的,我是从很久以前的某个地方复制它的,无法找回它来表示正确的信誉.如果您知道它的来源,请随时进行编辑并保留学分

This is not mine , I copied it from somewhere long back and cannot find it back to give proper credit . If you know where its from then feel free to edit and keep credits

这篇关于如何在线性布局中添加阴影-Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆