drawable,andrid 圆形图片,圆角图片
各种drawable 小的例子,
开源中国地址:https://git.oschina.net/lyxs916/drawable-test.git
![](https://images2015.cnblogs.com/blog/1082332/201703/1082332-20170312191553436-390100224.gif)
![](https://images2015.cnblogs.com/blog/1082332/201703/1082332-20170312184709045-2140481237.jpg)
bitmap
bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:antialias="false"
android:dither="true"
android:src="@mipmap/ic_launcher"
android:tileMode="mirror" <!--tileMode:显示的类型(repeat-重复的,mirror-镜像)
antialias:抗锯齿
dither;抖动
-->
bitmap
![](https://images2015.cnblogs.com/blog/1082332/201703/1082332-20170312185100061-830765118.jpg)
clip
<?xml version="1.0" encoding="utf-8"?>
clip xmlns:android="http://schemas.android.com/apk/res/android"
android:clipOrientation="horizontal"
android:drawable="@mipmap/y" <!--裁剪,可以控制大小,方向透明度-->
clip
inset
<?xml version="1.0" encoding="utf-8"?>
inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@color/colorAccent"
android:inset="20dp" <!--
插入一个背景
-->
inset
layer-list
<?xml version="1.0" encoding="utf-8"?>
layer-list xmlns:android="http://schemas.android.com/apk/res/android" item
android:width="150dp"
android:height="150dp"bitmap android:src="@mipmap/a" item
item
android:width="80dp"
android:height="80dp"
android:left="30dp"
android:top="50dp"bitmap android:src="@mipmap/y" item
item
android:width="50dp"
android:height="50dp"
android:left="40dp"
android:top="60dp"bitmap android:src="@mipmap/a" item
layer-list
level-list
<?xml version="1.0" encoding="utf-8"?>
level-list xmlns:android="http://schemas.android.com/apk/res/android" <!--根据不同的值显示不同的图片-->
item
android:drawable="@mipmap/a"
android:maxLevel="10"
android:minLevel="5"
item
android:drawable="@mipmap/y"
android:maxLevel="15"
android:minLevel="11"
item
android:drawable="@mipmap/ic_launcher"
android:maxLevel="4"
android:minLevel="0" level-list
selector
<?xml version="1.0" encoding="utf-8"?>
selector xmlns:android="http://schemas.android.com/apk/res/android" <!--这是一个状态的drawable,根据状态显示不同的图片-->
<!--获取焦点时-->
item android:drawable="@mipmap/a" android:state_focused="true" <!--选择时-->
item android:drawable="@mipmap/y" android:state_selected="true" <!--按压时-->
item android:drawable="@mipmap/g" android:state_pressed="true" <!--默认图-->
item android:drawable="@mipmap/ic_launcher" selector
transition
<?xml version="1.0" encoding="utf-8"?>
transition xmlns:android="http://schemas.android.com/apk/res/android" item android:drawable="@mipmap/a" item android:drawable="@mipmap/y" transition
/**
* 类说明:绘制圆形的drawable
* Created by 阳 2017/3/12 17:00
*/
public class extends private mPaintprivate mBitmapprivate int mWidth
public thismBitmap mPaint new //着色器
new mBitmapCLAMPCLAMPmPainttruemPaintmWidth minmBitmapmBitmap
@Override
public void
mWidth 2mWidth 2mWidth 2mPaint
@Override
public void int //设置画笔的透明度
mPaint
@Override
public void //设置颜色
mPaint
@Override
public int //设置不透明度
return TRANSLUCENT
@Override
public int //返回drawable实际宽
return mWidth
@Override
public int //返回drawable实际高
return mWidth
![](https://images2015.cnblogs.com/blog/1082332/201703/1082332-20170312185316967-11797533.jpg)
/**
* 类说明:绘制圆角的drawable
* Created by 阳 2017/3/12 17:00
*/
public class extends private mPaintprivate mBitmapprivate mRectFprivate int mRound
/**
* @param bitmap 位图
* @param round 圆角的值
*/
public int thismBitmap mPaint new //着色器
new mBitmapCLAMPCLAMPmPainttruemPaintmRound abs
@Override
public void mRectFmRoundmRoundmPaint
@Override
public void int int int int mRectF new
@Override
public void int //设置画笔的透明度
mPaint
@Override
public void //设置颜色
mPaint
@Override
public int //设置不透明度
return TRANSLUCENT
@Override
public int //返回 图片 实际宽
return mBitmap
@Override
public int //返回 图片 实际高
return mBitmap
![](https://images2015.cnblogs.com/blog/1082332/201703/1082332-20170312185345389-60648598.jpg)