6,gravity 属性详情
可选项 含义
top/bottom/left/right 将图片放在容器上 / 下 / 左 / 右, 不改变图片大小
center_vertical/horizontal 垂直居中 / 水平居中, 不改变图片大小
center 水平和垂直方向同时居中, 不改变图片大小
fill_vertical/horizontal 垂直 / 水平方向填充容器
fill 水平和垂直方向同时填充容器
clip_vertical/horizontal 垂直 / 水平方向的裁剪 - 较少使用
7,NinePatchDrawable(.9 图片) 的作用
Android 中的 Drawable 基础与自定义 Drawable
菠菜 bc 网站搭建架设, 需要请搜索 [大神源码论坛] http://dsluntan.com/forum.php 客服企娥 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"
- /> mailto:br/>
xmlns:android=
8,ShapeDrawable 的作用
通过颜色构造的图形
可以是纯色的图形
也可以是有渐变效果的图形
shape 标签创建的 Drawable 实体是 GradientDrawable
9,ShapeDrawable 的使用
- mailto:br/%3E%3Cnine-patch%3Cbr/%3Exmlns:android=
- <?xml version="1.0" encoding="utf-8"?>
- <shape
- xmlns:android="mailto:br/>
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 背景还是会被拉伸
来源: http://www.bubuko.com/infodetail-2767181.html