本文介绍了具有渐变边框和阴影的Android形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我为按钮绘制了一个png。但是它的可绘制图像具有渐变,当应用9patch时,它看起来很糟糕(渐变和9patch不兼容)。我想用形状做到这一点。但是我无法使用android形状进行绘制,因为这让我很难理解。
I have a png drawable for the buttons. But it image drawable has gradient and it looks bad when applying 9patch (gradient & 9patch non compatible). I want to do this with a shapes. But I can't drawing with android shapes because it's hard to me to understand it.
您能帮我用形状绘制此图像吗?
Can you help me to draw this image with a shapes?
它包含一个边框渐变,内部带有圆角的橙色矩形和阴影120°
It's contain a border gradient, orange rectangle inside with a rounded corners and shadow 120°
推荐答案
在这里
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#c8c0c0"
android:orientation="vertical">
<LinearLayout
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_centerInParent="true"
android:background="@drawable/my_rectangle">
</LinearLayout>
</RelativeLayout>
在可绘制文件夹内创建my_rectangle.xml文件
Create my_rectangle.xml file inside drawable folder
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:angle="270"
android:endColor="#000000"
android:startColor="#FFFFFF" />
<corners android:radius="10dp" />
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#e95d11" />
<corners android:radius="10dp" />
<size
android:width="50dp"
android:height="50dp" />
</shape>
</item>
</layer-list>
结果
The result
- 我将其设为120 * 120平方,更改尺寸以使其为矩形
- 我将圆角的半径设置为10dp,如果需要,可以更改它
- I将填充设为5dp,您也可以对其进行更改
欢呼声
这篇关于具有渐变边框和阴影的Android形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!