阴影布局,9补丁和背景颜色透明?

时间:2016-09-12 07:28:48

标签: android shadow nine-patch

我想添加一个带阴影的边缘的自定义布局,正好像这样: http://inloop.github.io/shadow4android/

问题是我使用它来添加半/透明背景颜色:(corners_main_layout.xml)

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="6dp" />
<solid android:color="@color/bright_foreground_disabled_material_dark" />
</shape>

所以我不能用于后台9-patch。

有没有办法用阴影和透明背景颜色进行9补丁?

如果不是......怎么能产生效果?

PS:我看过很多自定义XML来添加阴影,但都非常差。

这里的例子:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_recover_pass"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="...RecoverPassActivity"
android:background="@mipmap/fondo_01"
android:orientation="vertical">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/corners_main_layout">

</LinearLayout>

enter image description here

我需要阴影边框矩形白色(它是透明的)类似于示例9-patch

------------ --------------- EDIT 我修改了mi corners_main_layout.xml:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <corners android:radius="6dp" />
        <solid android:color="@color/bright_foreground_disabled_material_dark" />

    </shape>
</item>

<item android:drawable="@drawable/shadow_custom" />

和结果:-(: enter image description here

1 个答案:

答案 0 :(得分:1)

是啊!我有解决方案!

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <corners android:radius="6dp" />
        <solid android:color="@color/bright_foreground_disabled_material_dark" />
    </shape>
</item>
<item android:drawable="@drawable/shadow_custom_9patch"/>
</layer-list>

感谢您的帮助!