Android中的Drawable菠菜bc网站搭建架设基础与自定义Drawable

6、gravity属性详情

可选项 含义
top/bottom/left/right 将图片放在容器上/下/左/右,不改变图片大小
center_vertical/horizontal 垂直居中/水平居中,不改变图片大小
center 水平和垂直方向同时居中,不改变图片大小
fill_vertical/horizontal 垂直/水平方向填充容器
fill 水平和垂直方向同时填充容器
clip_vertical/horizontal 垂直/水平方向的裁剪-较少使用
7、NinePatchDrawable(.9图片)的作用
Android中的Drawable基础与自定义Drawable
菠菜bc网站搭建架设,需要请搜索【大神源码论坛】dsluntan.com 客服企娥3393756370 V信17061863513,
自动根据宽高进行缩放且不会失真
实际使用,可以直接引用图片或者通过XML描述
<?xml version="1.0" encoding="utf-8"?>android:src="@color/colorPrimary"
br/> xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@color/colorPrimary"
android:antialias="true"
android:dither="true"
android:filter="true"
android:gravity="center"
android:mipMap="false"
android:tileMode="disabled"
/>

8、ShapeDrawable的作用

通过颜色构造的图形
可以是纯色的图形
也可以是有渐变效果的图形
shape标签创建的Drawable实体是GradientDrawable
9、ShapeDrawable的使用

<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<corners
    android:radius="10dp"
    android:topLeftRadius="10dp"
    android:topRightRadius="10dp"
    android:bottomLeftRadius="10dp"
    android:bottomRightRadius="10dp"/>
<gradient
    android:angle="45"
    android:centerX="30"
    android:centerY="30"
    android:centerColor="@color/colorAccent"
    android:endColor="@color/colorPrimary"
    android:startColor="@color/colorPrimaryDark"
    android:gradientRadius="20"
    android:type="linear"
    android:useLevel="true" />
<padding
    android:left="10dp"
    android:top="10dp"
    android:right="10dp"
    android:bottom="10dp" />
<size
    android:width="200dp"
    android:height="200dp" />
<solid
    android:color="@color/colorPrimary"/>
<stroke
    android:width="10dp"
    android:color="@color/colorAccent"
    android:dashWidth="5dp"
    android:dashGap="3dp"/>

</shape>

10、ShapeDrawable的属性介绍

属性/标签 作用 备注
android:shape 图形的形状:rectangle矩形、oval椭圆、line横线、ring圆环 corners标签对应于矩形;line和ring通过stroke指定线的宽度和颜色; ring圆环有五个特殊的shape属性
corners标签 四个角的角度
gradient标签 渐变效果-android:angle表示渐变角度,必须为45的倍数 android:type指明渐变类型:linear线性,radial径向、sweep扫描
solid标签 纯色填充 与gradient标签排斥
stroke标签 描边 有描边线和虚线
size标签 表示shape的固有大小,并非最终显示的大小 没有时getIntrinsicWidth返回-1;能指明Drawable的固有宽高,但如果作为View背景还是会被拉伸

猜你喜欢

转载自blog.51cto.com/13968292/2174685