1. <?xmlversion= "1.0" encoding= "utf-8" ?>
  2. <shapexmlns:android="http://schemas.android.com/apk/res/android" >
  3. <gradient
  4. android:startColor="#3A3C39"
  5. android:endColor="#181818"
  6. android:angle="270"
  7. />
  8. <cornersandroid:radius="0dp" />
  9. </shape>
  10. android:background="@drawable/shape_background_grey"
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android">     <gradient          android:startColor="#3A3C39"          android:endColor="#181818"         android:angle="270"      />     <corners android:radius="0dp" /> </shape>android:background="@drawable/shape_background_grey" 


其中 android:angle="270"

代表方向, 270表示从上到下,180表示从右到左,默认从左
Java代码
  1. <shapexmlns:android= "http://schemas.android.com/apk/res/android"
  2. android:shape="rectangle" >
  3. <gradientandroid:type="radial" android:gradientRadius= "250"
  4. android:startColor="#E9E9E9" android:endColor= "#D4D4D4" />
  5. </shape>
  6. <shapexmlns:android="http://schemas.android.com/apk/res/android" >
  7. <gradientandroid:angle="0" android:startColor= "#FFdaf3fc"
  8. android:centerColor="#FFd4e9a9" android:endColor= "#FFdaf3fc" />
  9. </shape>
<shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle">    <gradient android:type="radial" android:gradientRadius="250"        android:startColor="#E9E9E9" android:endColor="#D4D4D4" /></shape><shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:angle="0" android:startColor="#FFdaf3fc"  android:centerColor="#FFd4e9a9" android:endColor="#FFdaf3fc"/></shape>


在这里要注意android:type="radial"类型的使用会有不同的效果

android:centerColor="#FFd4e9a9" 通常这个也不是被人常用

Java代码
  1. <?xmlversion= "1.0" encoding= "utf-8" ?>
  2. <shapexmlns:android="http://schemas.android.com/apk/res/android"
  3. android:shape="rectangle" >
  4. <gradientandroid:startColor="#509245" android:centerColor= "#3e8532"
  5. android:endColor="#509245" android:type= "linear" android:angle= "90"
  6. android:centerX="0.5" android:centerY= "0.5" />
  7. <paddingandroid:left="7dp" android:top= "7dp" android:right= "7dp"
  8. android:bottom="7dp" />
  9. <cornersandroid:radius="4dp" />
  10. </shape>
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"        android:shape="rectangle">        <gradient android:startColor="#509245" android:centerColor="#3e8532"                android:endColor="#509245" android:type="linear" android:angle="90"                android:centerX="0.5" android:centerY="0.5" />        <padding android:left="7dp" android:top="7dp" android:right="7dp"                android:bottom="7dp" />        <corners android:radius="4dp" /></shape>


android:shape 配置的是图形的形式,主要包括方形、圆形等,上边代码为方形。gradient节点主要配置起点颜色、终点颜色、中间点的坐标、中间点的颜色、渐变角度 (90度为上下渐变,0为左右渐变),padding节点主要配置上下左右边距,corners节点配置四周园角的半径。

更多相关文章

  1. Android修改AlertDialog的背景颜色
  2. Android(安卓)ListView里设置默认Item的背景颜色
  3. Android(安卓)之各种颜色
  4. 改变tab中indicator文本的颜色
  5. Android导航滑动文字渐变+底部指示条
  6. android 用 XML 自定义边框(只上下边框有色)
  7. Android实现圆角ListView效果
  8. Android中shape中的属性大全
  9. Android(安卓)补间动画(动画列表,平移,旋转,缩放,渐变,动画集合)

随机推荐

  1. mysql脏页是什么
  2. 为什么MySQL分页用limit会越来越慢
  3. MySQL深度分页(千万级数据量如何快速分页
  4. ORM模型框架操作mysql数据库的方法
  5. mysql 直接拷贝data 目录下文件还原数据
  6. MySQL 四种连接和多表查询详解
  7. MySQL索引是啥?不懂就问
  8. MySQL 聚合函数排序
  9. MySQL 那些常见的错误设计规范,你都知道
  10. MySQL 5.7常见数据类型