【发布时间】:2016-07-15 14:12:56
【问题描述】:
我想创建一个可绘制对象并将其用作按钮的背景。 阴影的高度必须为 18dip。看图。
我已经尝试过这种方式,但它不起作用:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false">
<layer-list>
<item android:gravity="bottom">
<bitmap android:src="@drawable/shadow9path"/> // This is a 9-path picture
</item>
<item android:gravity="bottom"
android:bottom="18dp">
<shape android:shape="rectangle">
<size android:height="@dimen/..." />
<corners android:radius="@dimen/..." />
<solid android:color="@color/..." />
</shape>
</item>
</layer-list>
</item>
...
</selector>
编辑: 阴影应该只在按钮的底部。所以按钮不应该被阴影包围。我需要一个复合视图之类的东西,它由按钮和它下面的阴影组成。
【问题讨论】:
-
不幸的是不是我看的雾。阴影应该只在按钮的底部。我会更新问题。
-
<bitmap android:src="@drawable/shadow9path"/> // This is a 9-path picture如果是9补丁,那你为什么用bitmap?你应该使用nine-patch:developer.android.com/guide/topics/resources/… -
@BobMalooga 将位图更改为九个补丁并不能解决问题:(
-
好的,但是为什么要使用 LayerList?一个包含阴影的简单背景会更容易做到这一点!你真的不要
need something like a compound view, which consists of the button and the shadow below it.
标签: android xml xml-drawable