当前位置: 首页 > news >正文

圆点虚线 Android

参考 https://blog.csdn.net/l_o_s/article/details/73550876

<com.xxx.wwww.weight.PointDividerViewandroid:layout_width="match_parent"android:layout_height="wrap_content"app:PDbackgroundColor="@color/white"app:dotColor="@color/com_red"app:dotRadius="2dp"app:dividerWidth="5dp"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" />

 attrs.xml

<declare-styleable name="PointDividerView"><!--自定义圆点的半径大小--><attr name="dotRadius" format="dimension" /><!--圆点的间距--><attr name="dividerWidth" format="dimension" /><!--圆点颜色--><attr name="dotColor" format="color" /><!--虚线背景颜色--><attr name="PDbackgroundColor" format="color" /></declare-styleable>

 


import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;import androidx.annotation.Nullable;import com.feishi.pettyloan.R;/*** https://blog.csdn.net/l_o_s/article/details/73550876* Created by Lyf on 2017/6/5.* 撸一串圆点做分割线 圆点分割线*/
public class PointDividerView extends View {private Paint mPaint; // 画笔private float radius; // 圆的半径private float dividerWidth; // 圆的间距private int mColor; // 圆点的颜色private int mBackgroundColor; // 背景颜色private Context mContext;public PointDividerView(Context context) {super(context);init(context, null);}public PointDividerView(Context context, @Nullable AttributeSet attrs) {super(context, attrs);init(context, attrs);}public PointDividerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);init(context, attrs);}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {super.onMeasure(widthMeasureSpec, heightMeasureSpec);setMeasuredDimension(widthMeasureSpec, dip2px(10));}protected void init(Context context, @Nullable AttributeSet attrs) {mContext = context;mPaint = new Paint();if (attrs != null) {TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PointDividerView);radius = a.getDimension(R.styleable.PointDividerView_dotRadius, dip2px(1));dividerWidth = a.getDimension(R.styleable.PointDividerView_dividerWidth, dip2px(6));mColor = a.getColor(R.styleable.PointDividerView_dotColor, Color.parseColor("#d1d1d1"));mBackgroundColor = a.getColor(R.styleable.PointDividerView_PDbackgroundColor, Color.TRANSPARENT);a.recycle();} else {radius = dip2px(1);dividerWidth = dip2px(6);mColor = Color.parseColor("#d1d1d1");mBackgroundColor = Color.TRANSPARENT;}}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);// 绘制背景canvas.drawColor(mBackgroundColor);mPaint.setAntiAlias(true);mPaint.setColor(mColor); // 设置颜色int measuredHeight = getMeasuredHeight() / 2; // 高度居中int measuredWidth = getMeasuredWidth();for (float i = radius; i < measuredWidth; ) {canvas.drawCircle(i, measuredHeight, radius, mPaint); // 小圆i += dividerWidth;}}private int dip2px(float dip) { // Metrics(满锤思)测量density(扽思提)密度float density = getContext().getResources().getDisplayMetrics().density;return (int) (dip * density + 0.5f);}
}

http://www.lryc.cn/news/471760.html

相关文章:

  • 贵州鑫宏远农业-始终致力于推动现代农业的科技创新与发展
  • 程序员做销售,从代码到客户的逆袭之路
  • Flink CDC系列之:理解学习Kubernetes模式
  • git合并相关操作详解
  • 前端经典【面试题】持续更新HTML、CSS、JS、VUE、FLUTTER、性能优化等
  • 【Linux知识】linux磁盘管理深入了解
  • Qt Essential Classes
  • 小小猫棒onu替换家用光猫,薅运营商带宽羊毛,突破1000M
  • 软件测试学习笔记丨Selenium学习笔记:css定位
  • python数据处理常用操作
  • 解决minio跨域问题
  • python 跳过当前循环
  • 数据库数据恢复—Oracle ASM磁盘组掉线 ,ASM实例无法挂载的数据恢复案例
  • jupyter notebook改变默认启动路径
  • libevent源码剖析-基本数据结构
  • 往期文章汇总——射频测量+无线通信+软件无线电+6G科普
  • 微信小程序 - 深 / 浅拷贝实现方法,微信小程序深拷贝与浅拷贝,函数方法封装直接调用使用,深拷贝cloneDeep和浅拷贝clone(深复制和浅复制)
  • Log4Net配置详解及输出自定义消息类示例代码
  • C++在实际项目中的应用第二节:C++与区块链
  • 浅记React面试丢人时刻
  • Python入门:学会Python装饰器让你的代码如虎添翼!(Python如何不改动原有函数代码添加一些额外的功能)
  • 【C++】哈希冲突的解决办法:闭散列 与 开散列
  • 复刻系列-原神 5.1 版本先行展示页
  • STM32 第3章 如何用串口下载程序
  • HT71782 20V,15A全集成同步升压转换器
  • [含文档+PPT+源码等]精品基于PHP实现的培训机构信息管理系统的设计与实现
  • 亚信安全DeepSecurity中标知名寿险机构云主机安全项目
  • 论文解析八: GAN:Generative Adversarial Nets(生成对抗网络)
  • 【ARM】ARM架构参考手册_Part B 内存和系统架构(2)
  • HttpServer模块 --- 封装TcpServer支持Http协议