在Android中,很多时候系统原生的控件的格式并不能满足我们的需求,我们想要更加好看点的样式,像什么圆角矩形啊,颜色渐变啊,阴影效果啊等等的,这个时候就是我们的ShapeDrawable发挥效果的时候了,接下来我们这两篇文章就来说一下Shape的一些应用吧,掌握点基础知识,才能好好更好地去应用啊。
其实很多东西并不难,我们也不是不懂,但是关键得懂得总结呀,对吧。
1)首先,我们要在res/drawable/ 路径下创建一个xml文件,其格式如下(这是在Android的官方文档中拿出来的,我觉得真的很丰满,一目了然):
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape=["rectangle" | "oval" | "line" | "ring"] >
<corners
android:radius="integer"
android:topLeftRadius="integer"
android:topRightRadius="integer"
android:bottomLeftRadius="integer"
android:bottomRightRadius="integer" />
<gradient
android:angle="integer"
android:centerX="integer"
android:centerY="integer"
android:centerColor="integer"
android:endColor="color"
android:gradientRadius="integer"
android:startColor="color"
android:type=["linear" | "radial" | "sweep"]
android:useLevel=["true" | "false"] />
<padding
android:left="integer"
android:top="integer"
android:right="integer"