shape相关属性详解

1.gradient渐变

<gradient  android:angle="integer"  android:centerX="Float"  android:centerY="Float"  android:centerColor="integer"  android:startColor="color"  android:endColor="color"  android:gradientRadius="integer"  android:type=["linear"|"radial"|"sweep"]  android:usesLevel=["true"|"false"]  />

angle:角度,当 android:type=“linear”时有效
centerX:Float。渐变色中心的 X 相对位置( 0-1.0 )。当 android:type=“linear”时无效
centerY:Float。渐变色中心的 Y 相对位置( 0-1.0 )。当 android:type=“linear”时无效
centerColor:color。可选的颜色,出现在 start 和 end 颜色之间。
gradientRadius:Float。渐变色的半径。当 android:type=“radial” 时有效。
startcolor:开始的颜色
endcolor:结束的颜色
type:Keyword 。渐变色的样式。有效值为:
“linear”:线性渐变,默认值
“radial”:环形渐变。 start 颜色是处于中间的颜色
“sweep”:sweep 渐变
useLevel:Boolean。“ true ”表示可以当作 LevelListDrawable 使用

1.1 android:type=”linear”
例如:在res/drawable下建立一个gradient_shape.xml文件:

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" >    <gradient android:startColor="#fff" android:endColor="#000" android:centerColor="#dc143c" android:angle="45"/></shape>

在res/layout里新建一个activity_gradient.xml文件:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/back_shape" android:orientation="vertical" ></LinearLayout>

截图:
Shape的相关属性详解_第1张图片

android:startColor=”#fff”起始颜色为白色
android:endColor=”#000”结束颜色为黑色
android:centerColor=”#dc143c”中间色为红色
android:angle=”45”渐变角度为45度,从左下到右上

1.2 android:type=”radial”

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" >    <gradient android:startColor="#fff" android:endColor="#000" android:centerColor="#dc143c" android:gradientRadius="90" android:type="radial" /></shape>

截图:

这里颜色渐变的是里向外渐变
android:startColor=”#fff”起始(最里)颜色为白色
android:endColor=”#000”结束(最外)颜色为黑色
android:centerColor=”#dc143c”中间颜色为红色
android:gradientRadius=”90”渐变半径为90
android:type=”radial”类型为环形渐变

1.3 android:type=”sweep”

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" >    <gradient android:startColor="#fff" android:endColor="#000" android:centerColor="#dc143c" android:centerX="0" android:centerY="0" android:type="sweep" /></shape>

截图:
Shape的相关属性详解_第2张图片

android:startColor=”#fff”起始颜色为白色
android:endColor=”#000”结束颜色为黑色
android:centerColor=”#dc143c”中间色为红色
android:centerX=”0”渐变色中心的 X 相对位置( 0-1.0 )。当android:type=“linear”时无效
android:centerY=”0”渐变色中心的 Y 相对位置( 0-1.0 )。当 android:type=“linear”时无效
android:type=”sweep”延伸类型

2 . corners 圆角

<corners  android:radius="integer" android:topLeftRadius="integer" android:topRightRadius="integer" android:bottomLeftRadius="integer" android:bottomRightRadius="integer" />

corners–>圆角
radius:半径,会被下面的特性覆盖。
topLeftRadius:左上圆角半径。
topRightRadius:右上圆角半径。
bottomLeftRadius:左下圆角半径。
bottomRightRadius:右下圆角半径。

3 . padding各个方向的间距

<!-- 间隔 -->    <padding  android:left="2dp" android:top="2dp" android:right="2dp" android:bottom="2dp"/><!-- 各方向的间隔 -->

4 . size尺寸大小

 <!-- 大小 -->    <size  android:width="100dp" android:height="50dp"/><!-- 宽度和高度 -->

5 . solid背景色填充

<!-- 填充 -->    <solid  android:color="@android:color/white"/>

6 . stroke描边

<!-- 描边 -->     <stroke  android:width="2dp" android:color="#a9a9a9" android:dashWidth="2dp" android:dashGap="1dp"/>

android:width=”2dp” 设置边边的宽度
android:color=”#a9a9a9” 设置边边的颜色
android:dashWidth=”2dp” 设置虚线的宽度
android:dashGap=”1dp” 设置虚线的间隔宽度

更多相关文章

  1. Android 中颜色对应的代码集合
  2. Android沉浸式(设置状态栏颜色)
  3. 设置android的布局文件的背景颜色为黑色
  4. android 获取屏幕的宽度和高度
  5. Android 动态设置颜色
  6. Android Textview实现颜色渐变滚动效果
  7. Android Studio——Android获取屏幕宽度的4种方法
  8. Android TextView内容设置超链接、颜色、字体
  9. Android原生AlertDialog修改标题,内容,按钮颜色,字体大小等

随机推荐

  1. 如何利用Activity的Dialog风格完成弹出框
  2. 通过layer-list多图层叠加效果实现圆角功
  3. Android监听ListView停止的时候是不是滑
  4. android中不同app间数据交互(1、简单一次
  5. Android大屏项目中的数字键盘输入界面的
  6. 自定义Android电子时钟控件
  7. Android通讯录查询篇--ContactsContract.
  8. Android自定义控件系列案例【四】
  9. 【Android】Android中判断后台服务是否正
  10. Android(安卓)记一次解决问题的过程:从源