最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

android九宮格鎖屏控件使用詳解

 更新時間:2022年06月28日 08:51:27   作者:poorSir  
這篇文章主要為大家詳細介紹了android九宮格鎖屏控件使用,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了android九宮格鎖屏控件的具體代碼,供大家參考,具體內(nèi)容如下

代碼:

public class LockView extends View {
? ? //半徑
? ? private int radius;
? ? //中心小圓半徑
? ? private int smallRadius;
? ? //一行個數(shù)
? ? private int column;
? ? //選中顏色
? ? private int selectColor;
? ? //未選中顏色
? ? private int normalColor;
? ? //陰影顏色
? ? private int shaderColor;
? ? //連線的顏色
? ? private int lineColor;
? ? //圓線寬
? ? private int circleStrokeWidth;
? ? //連線的線寬
? ? private int lineStrokeWidth;

? ? private Paint normalPaint;
? ? private Paint selectPaint;
? ? private Paint linePaint;
? ? private Paint centerPaint;
? ? private int width;
? ? //每個圓寬度
? ? private int everyWidth;
? ? //是否是選中繪制
? ? private boolean isSelect;
? ? //所有圓信息
? ? private List<Point> allCircleList = new ArrayList<>();
? ? //選中圓的標志
? ? private List<Integer> selectList = new ArrayList<>();
? ? //是否是重置
? ? private boolean isReSet;
? ? private LockViewFinishListener lockViewFinishListener;

? ? public LockView(Context context, @Nullable AttributeSet attrs) {
? ? ? ? super(context, attrs);
? ? ? ? init(context, attrs);
? ? }

? ? public LockViewFinishListener getLockViewFinishListener() {
? ? ? ? return lockViewFinishListener;
? ? }

? ? public void setLockViewFinishListener(LockViewFinishListener lockViewFinishListener) {
? ? ? ? this.lockViewFinishListener = lockViewFinishListener;
? ? }

? ? private void init(Context context, AttributeSet attrs) {
? ? ? ? TypedArray typedArray = context.obtainStyledAttributes(attrs,R.styleable.LockView);
? ? ? ? radius = typedArray.getInteger(R.styleable.LockView_lock_radius,100);
? ? ? ? smallRadius = typedArray.getInteger(R.styleable.LockView_smallRadius,30);
? ? ? ? column = typedArray.getInteger(R.styleable.LockView_column,3);
? ? ? ? selectColor =typedArray.getColor(R.styleable.LockView_selectColor,Color.RED);
? ? ? ? normalColor = typedArray.getColor(R.styleable.LockView_lock_normalColor,Color.GRAY);
? ? ? ? shaderColor = typedArray.getColor(R.styleable.LockView_shaderColor,Color.argb(80, 0xff, 0x00, 0x00));
? ? ? ? lineColor = typedArray.getColor(R.styleable.LockView_lineColor,Color.RED);
? ? ? ? circleStrokeWidth = typedArray.getInteger(R.styleable.LockView_circleStrokeWidth,5);
? ? ? ? lineStrokeWidth = typedArray.getInteger(R.styleable.LockView_lineStrokeWidth,15);

? ? ? ? normalPaint = new Paint();
? ? ? ? normalPaint.setColor(normalColor);
? ? ? ? normalPaint.setAntiAlias(false);//設置為無鋸齒
? ? ? ? normalPaint.setStrokeWidth(circleStrokeWidth);//線寬
? ? ? ? normalPaint.setStyle(Paint.Style.STROKE);

? ? ? ? selectPaint = new Paint();
? ? ? ? selectPaint.setColor(selectColor);
? ? ? ? selectPaint.setAntiAlias(false);
? ? ? ? selectPaint.setStrokeWidth(circleStrokeWidth);
? ? ? ? selectPaint.setStyle(Paint.Style.STROKE);

? ? ? ? centerPaint = new Paint();
? ? ? ? centerPaint.setColor(selectColor);
? ? ? ? centerPaint.setAntiAlias(false);
? ? ? ? centerPaint.setStrokeWidth(radius - smallRadius);
? ? ? ? centerPaint.setStyle(Paint.Style.FILL_AND_STROKE);

? ? ? ? linePaint = new Paint();
? ? ? ? linePaint.setColor(lineColor);
? ? ? ? linePaint.setAntiAlias(false);//設置為無鋸齒
? ? ? ? linePaint.setStrokeWidth(lineStrokeWidth);//線寬
? ? ? ? linePaint.setAlpha(150);
? ? ? ? linePaint.setStyle(Paint.Style.STROKE);
? ? }

? ? @Override
? ? protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
? ? ? ? width = measureWidth(widthMeasureSpec);
? ? ? ? setMeasuredDimension(width, width);
? ? ? ? everyWidth = (width - getPaddingLeft() - getPaddingRight()) / column;
? ? ? ? allCircleList.clear();
? ? ? ? for (int i = 0; i < column; i++) {
? ? ? ? ? ? for (int j = 0; j < column; j++) {
? ? ? ? ? ? ? ? float cx = getPaddingLeft() + everyWidth / 2 * (2 * j + 1);
? ? ? ? ? ? ? ? float cy = getPaddingTop() + everyWidth / 2 * (2 * i + 1);
? ? ? ? ? ? ? ? Point point = new Point();
? ? ? ? ? ? ? ? point.cx = cx;
? ? ? ? ? ? ? ? point.cy = cy;
? ? ? ? ? ? ? ? allCircleList.add(point);
? ? ? ? ? ? }
? ? ? ? }
? ? }

? ? @Override
? ? protected void onDraw(Canvas canvas) {
? ? ? ? super.onDraw(canvas);
? ? ? ? for (int i = 0; i < allCircleList.size(); i++) {
? ? ? ? ? ? Point point = allCircleList.get(i);
? ? ? ? ? ? canvas.drawCircle(point.cx, point.cy, radius, normalPaint);
? ? ? ? }
? ? ? ? if (isReSet) {//重置
? ? ? ? ? ? isReSet = false;
? ? ? ? ? ? postInvalidate();
? ? ? ? } else {
? ? ? ? ? ? if (isSelect) {
? ? ? ? ? ? ? ? for (int i = 0; i < selectList.size(); i++) {
? ? ? ? ? ? ? ? ? ? int index = selectList.get(i);
? ? ? ? ? ? ? ? ? ? Point point = allCircleList.get(index);
? ? ? ? ? ? ? ? ? ? canvas.drawCircle(point.cx, point.cy, radius, selectPaint);
? ? ? ? ? ? ? ? ? ? Shader mShader = new RadialGradient(point.cx, point.cy, smallRadius, new int[]{selectColor, shaderColor},
? ? ? ? ? ? ? ? ? ? ? ? ? ? new float[]{0.9f, 1f}, Shader.TileMode.CLAMP);
? ? ? ? ? ? ? ? ? ? centerPaint.setShader(mShader);
? ? ? ? ? ? ? ? ? ? canvas.drawCircle(point.cx, point.cy, smallRadius, centerPaint);
? ? ? ? ? ? ? ? ? ? if (i >= 1) {
? ? ? ? ? ? ? ? ? ? ? ? int lastIndex = selectList.get(i - 1);
? ? ? ? ? ? ? ? ? ? ? ? Point lastPoint = allCircleList.get(lastIndex);
? ? ? ? ? ? ? ? ? ? ? ? canvas.drawLine(lastPoint.cx, lastPoint.cy, point.cx, point.cy, linePaint);
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }

? ? @Override
? ? public boolean onTouchEvent(MotionEvent event) {
? ? ? ? switch (event.getAction()) {
? ? ? ? ? ? case MotionEvent.ACTION_DOWN:
? ? ? ? ? ? ? ? isReSet = true;
? ? ? ? ? ? ? ? selectList.clear();

? ? ? ? ? ? ? ? int index = calculateWhich(event.getX(), event.getY());
? ? ? ? ? ? ? ? if (index != -1) {
? ? ? ? ? ? ? ? ? ? selectList.add(index);
? ? ? ? ? ? ? ? ? ? isSelect = true;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case MotionEvent.ACTION_MOVE:
? ? ? ? ? ? ? ? index = calculateWhich(event.getX(), event.getY());
? ? ? ? ? ? ? ? if (index != -1) {
? ? ? ? ? ? ? ? ? ? if (!selectList.contains(index)) {
? ? ? ? ? ? ? ? ? ? ? ? selectList.add(index);
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case MotionEvent.ACTION_UP:
? ? ? ? ? ? ? ? if (lockViewFinishListener != null) {
? ? ? ? ? ? ? ? ? ? StringBuffer result = new StringBuffer();
? ? ? ? ? ? ? ? ? ? for (int i = 0; i < selectList.size(); i++) {
? ? ? ? ? ? ? ? ? ? ? ? result.append(selectList.get(i));
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? lockViewFinishListener.onSuccess(result + "");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? postInvalidate();
? ? ? ? return true;
? ? }

? ? /**
? ? ?* 計算控件寬高
? ? ?*
? ? ?* @param widthMeasureSpec
? ? ?* @return
? ? ?*/
? ? private int measureWidth(int widthMeasureSpec) {
? ? ? ? int result;
? ? ? ? int specSize = MeasureSpec.getSize(widthMeasureSpec);
? ? ? ? int specMode = MeasureSpec.getMode(widthMeasureSpec);
? ? ? ? if (specMode == MeasureSpec.EXACTLY) {
? ? ? ? ? ? result = specSize;
? ? ? ? } else {
? ? ? ? ? ? result = getPaddingLeft() + getPaddingRight() + radius * 2 * column ;
? ? ? ? ? ? if (specMode == MeasureSpec.AT_MOST) {
? ? ? ? ? ? ? ? result = Math.min(result, specSize);
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return result;
? ? }

? ? /**
? ? ?* 計算是在哪個圓中
? ? ?*
? ? ?* @return
? ? ?*/
? ? private int calculateWhich(float lx, float ly) {
? ? ? ? for (int i = 0; i < allCircleList.size(); i++) {
? ? ? ? ? ? Point point = allCircleList.get(i);
? ? ? ? ? ? if (lx > point.cx - radius && lx < point.cx + radius) {
? ? ? ? ? ? ? ? if (ly > point.cy - radius && ly < point.cy + radius) {
? ? ? ? ? ? ? ? ? ? return i;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return -1;
? ? }

? ? public interface LockViewFinishListener {
? ? ? ? void onSuccess(String result);
? ? }

? ? private class Point {
? ? ? ? private float cx;
? ? ? ? private float cy;
? ? }

}
<!--九宮格鎖屏控件-->
? ? <declare-styleable name="LockView">
? ? ? ? <!--大圓半徑-->
? ? ? ? <attr name="lock_radius" format="integer"/>
? ? ? ? <!--小圓半徑-->
? ? ? ? <attr name="smallRadius" format="integer"/>
? ? ? ? <!--一行個數(shù)-->
? ? ? ? <attr name="column" format="integer"/>
? ? ? ? <!--選中顏色-->
? ? ? ? <attr name="selectColor" format="color"/>
? ? ? ? <!--未選中顏色-->
? ? ? ? <attr name="lock_normalColor" format="color"/>
? ? ? ? <!--陰影顏色-->
? ? ? ? <attr name="shaderColor" format="color"/>
? ? ? ? <!--連線的顏色-->
? ? ? ? <attr name="lineColor" format="color"/>
? ? ? ? <!--圓線寬-->
? ? ? ? <attr name="circleStrokeWidth" format="integer"/>
? ? ? ? <!--連線的線寬-->
? ? ? ? <attr name="lineStrokeWidth" format="integer"/>
</declare-styleable>

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android實現(xiàn)全屏截圖或長截屏功能

    Android實現(xiàn)全屏截圖或長截屏功能

    這篇文章主要為大家詳細介紹了Android實現(xiàn)全屏截圖或長截屏功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • Android中NavigationView的使用與相關(guān)問題解決

    Android中NavigationView的使用與相關(guān)問題解決

    大家都知道NavigationView的引入讓 Android側(cè)邊欄實現(xiàn)起來相當方便,最近公司項目中也使用這個新的控件完成了側(cè)邊欄的改版。在使用過程中遇到一些問題所以記錄一下。本文分為兩個部分,一是基本使用,二是相關(guān)問題的解決,感興趣的朋友們下面來一起看看吧。
    2016-10-10
  • 快速解決Android適配底部返回鍵等虛擬鍵盤的問題

    快速解決Android適配底部返回鍵等虛擬鍵盤的問題

    今天小編就為大家分享一篇快速解決Android適配底部返回鍵等虛擬鍵盤的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-07-07
  • Android實現(xiàn)購物車添加物品的動畫效果

    Android實現(xiàn)購物車添加物品的動畫效果

    本文主要介紹了Android實現(xiàn)購物車添加物品動畫效果的示例代碼。具有很好的參考價值,下面跟著小編一起來看下吧
    2017-03-03
  • Android仿天貓橫向滑動指示器功能的實現(xiàn)

    Android仿天貓橫向滑動指示器功能的實現(xiàn)

    這篇文章主要介紹了Android仿天貓橫向滑動指示器,Android開發(fā)中會有很多很新奇的交互,比如天貓商城的首頁頭部的分類,使用的是GridLayoutManager+橫向指示器實現(xiàn)的,需要的朋友可以參考下
    2022-08-08
  • Android table布局開發(fā)實現(xiàn)簡單計算器

    Android table布局開發(fā)實現(xiàn)簡單計算器

    這篇文章主要為大家詳細介紹了Android table布局開發(fā)實現(xiàn)簡單計算器,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-05-05
  • Android控件之Spinner用法實例分析

    Android控件之Spinner用法實例分析

    這篇文章主要介紹了Android控件之Spinner用法,以實例形式較為詳細的分析了Spinner控件模擬下拉列表的實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-09-09
  • Android實現(xiàn)購物車功能

    Android實現(xiàn)購物車功能

    這篇文章主要為大家詳細介紹了Android實現(xiàn)購物車功能的具體方法 ,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-02-02
  • Android中TabLayout添加小紅點的示例代碼

    Android中TabLayout添加小紅點的示例代碼

    本篇文章主要介紹了Android中TabLayout添加小紅點的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-12-12
  • Android保存Activity狀態(tài)的方法

    Android保存Activity狀態(tài)的方法

    這篇文章主要介紹了Android保存Activity狀態(tài)的方法,結(jié)合實例形式較為詳細的分析了Android保存Activity狀態(tài)的原理、實現(xiàn)步驟及相關(guān)注意事項,需要的朋友可以參考下
    2016-08-08

最新評論

灌南县| 松潘县| 房产| 厦门市| 凤城市| 海安县| 衡阳市| 通山县| 安龙县| 贵阳市| 漯河市| 耒阳市| 抚松县| 布尔津县| 砀山县| 莲花县| 河东区| 桓仁| 红河县| 孟津县| 漳平市| 德化县| 和林格尔县| 永安市| 延长县| 大石桥市| 玛沁县| 鄂尔多斯市| 呼玛县| 西贡区| 汕头市| 三原县| 江山市| 宜城市| 宝兴县| 井冈山市| 德令哈市| 进贤县| 雷州市| 儋州市| 师宗县|