设为首页 加入收藏

TOP

实用控件分享:自定义逼真相机光圈View(三)
2017-10-13 10:35:52 】 浏览:8631
Tags:实用 控件 分享 定义 逼真 相机 光圈 View
Points[2].y = 0; 172 mPoints[3].x = mPoints[1].x; 173 mPoints[3].y = -mPoints[1].y; 174 mPoints[4].x = -mPoints[3].x; 175 mPoints[4].y = mPoints[3].y; 176 mPoints[5].x = curRadius; 177 mPoints[5].y = 0; 178 } 179 180 //创建光圈叶片,让美工MM提供更好 181 private void createBlade() { 182 mBlade = Bitmap.createBitmap(mCircleRadius, 183 (int) (mCircleRadius * 2 * COS_30), Config.ARGB_8888); 184 Path path = new Path(); 185 Canvas canvas = new Canvas(mBlade); 186 path.moveTo(mSpace / 2 / COS_30, mSpace); 187 path.lineTo(mBlade.getWidth(), mBlade.getHeight()); 188 path.lineTo(mBlade.getWidth(), mSpace); 189 path.close(); 190 canvas.clipPath(path); 191 canvas.drawColor(mBladeColor); 192 } 193 194 /** 195 * 设置光圈片的颜色 196 * @param bladeColor 197 */ 198 public void setBladeColor(int bladeColor) { 199 mBladeColor = bladeColor; 200 } 201 202 /** 203 * 设置光圈背景色 204 */ 205 public void setBackgroundColor(int backgroundColor) { 206 mBackgroundColor = backgroundColor; 207 } 208 209 /** 210 * 设置光圈片之间的间隔 211 * @param space 212 */ 213 public void setSpace(int space) { 214 mSpace = space; 215 } 216 217 /** 218 * 设置光圈最大值 219 * @param maxApert 220 */ 221 public void setMaxApert(float maxApert) { 222 mMaxApert = maxApert; 223 } 224 225 /** 226 * 设置光圈最小值 227 * @param mMinApert 228 */ 229 public void setMinApert(float mMinApert) { 230 this.mMinApert = mMinApert; 231 } 232 233 public float getCurrentApert() { 234 return mCurrentApert; 235 } 236 237 public void setCurrentApert(float currentApert) { 238 if (currentApert > mMaxApert) { 239 currentApert = mMaxApert; 240 } 241 if (currentApert < mMinApert) { 242 currentApert = mMinApert; 243 } 244 if (mCurrentApert == currentApert) { 245 return; 246 } 247 mCurrentApert = currentApert; 248 invalidate(); 249 if (mApertureChanged != null) { 250 mApertureChanged.onApertureChanged(currentApert); 251 } 252 } 253 254 /** 255 * 设置光圈值变动的监听 256 * @param listener 257 */ 258 public void setApertureChangedListener(ApertureChanged listener) { 259 mApertureChanged = listener; 260 } 261 }

自定义属性的xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="ApertureView">
        <attr name="blade_color" format="color" />
        <attr name="background_color" format="color" />
        <attr name="blade_space" format="dimension" />
    </declare-styleable>
</resources>

 

首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇使用异步任务加载网络上json数据.. 下一篇Android开发学习之路-Android中使..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目