Shape
2016-12-10 00:25
134 查看
前言
本文对shape做个介绍,以及圆角矩形与layer-list主要元素
gradient – 对应颜色渐变。 startcolor、endcolor就不多说了。 android:angle 是指从哪个角度开始变。solid – 填充。
stroke – 描边。
corners – 圆角。
padding – 定义内容离边界的距离。与android:padding_left、android:padding_right这些是一个理。
圆角矩形
先抛出结论,圆角矩形的代码如下所示。<?xml version="1.0" encoding="utf-8"?><!--圆角矩形--> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!--圆角半径--> <corners android:radius="15dp" /> <!--填充--> <solid android:color="@color/white" /> <!--描边--> <stroke android:width="1px" android:color="@color/black"></stroke> </shape>
这里有个坑,以前我是不写solid的,觉得没必要,后来发现在4.1.2的手机上出来的shape背景是黑色的,我擦,看来solid必须要写的。
layer-list
有时候可以用多个shape叠加来实现想要的效果,用layer-list<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <stroke android:color="#00ff00" android:width="1px"></stroke> <solid android:color="#00ffee"></solid> </shape> </item> <item android:bottom="15dp"> <shape android:shape="rectangle"> <solid android:color="#003f77"></solid> </shape> </item> </layer-list>
以上代码就是2个shape的叠加效果如下
相关文章推荐
- Android开发:shape和selector和layer-list的(详细说明)
- 使用shape绘制阴影图层阴影效果
- selector和shape的混搭使用
- Shape + Selector: Make a Shape as one item of the Selector
- 自定义drawable android:shape
- 形状资源(shape)
- DialogFragment背景shape圆角bottom无效
- android shape的使用
- ASM(active shape models)算法介绍
- shape标签总结
- Shape与DrawableCompat
- android shape的使用
- 背水一战 Windows 10 (12) - 绘图: Shape, Path
- Android开发之Shape和Selector、Layer-list的详解
- 写一个程序,定义抽象基类Shape,由它派生出3个派生类,Circle(圆形)、Rectangle(矩形)、Triangle(三角形)。用如下的main()函数,求出定义的几个几何体的面积和
- Android:自定义Shape 加上阴影shadow之方法
- android shape
- Unity Shape sdk 安卓问题
- <Android 基础(十三)> shape
- Android背景渐变色(shape,gradient)