Android仿天眼查人物关系图

效果图预览

绘制思路

这里使用了中学解析几何知识 XPoint = OPointX = OPointXcosθ; YPoint = OPointY = OPointYsinθ;

复制代码
canvas.drawText(lists.get(i).getName(), XPoint + (float) Math.cos(pere * i + 5) * radius[i % radius.length] - 30, YPoint + (float) Math.sin(pere * i + 5) * radius[i % radius.length] + 35, paint);

用法

复制代码
1、XML布局(PS要根据自己的包名) <com.gkzy.relation.CirclePeopleView
   android:id="@+id/layout_cricle_people"
   android:layout_width="match_parent"
   android:layout_height="280dp"
   app:layout_constraintBottom_toBottomOf="parent"
   app:layout_constraintLeft_toLeftOf="parent"
   app:layout_constraintRight_toRightOf="parent"
   app:layout_constraintTop_toTopOf="parent" />
  
       
2.  peopleView = findViewById(R.id.layout_cricle_people);

3. 添加数据,刷新UI peopleView.SetFieldInfo(lists);
   peopleView.invalidate();
   
   
4.添加了view的点击事件,通过手势判断。原理:
每个圆的Cx,Cy,r都能获取到,然后通过已知数据计算RectF的
 left,  top,  right,  bottom
  /**
    * Create a new rectangle with the specified coordinates. Note: no range
    * checking is performed, so the caller must ensure that left <= right and
    * top <= bottom.
    *
    * @param left   The X coordinate of the left side of the rectangle
    * @param top    The Y coordinate of the top of the rectangle
    * @param right  The X coordinate of the right side of the rectangle
    * @param bottom The Y coordinate of the bottom of the rectangle
    */
   public RectF(float left, float top, float right, float bottom) {
       this.left = left;
       this.top = top;
       this.right = right;
       this.bottom = bottom;
   }
   
   得到RectF后判断contains(x,y)来获得点击的位置

项目源码:GitHub - chenhua1008611/Co-People: 仿天眼查关系图的生成,自定义view,随机颜色,随机大小

相关推荐
2501_9159214327 分钟前
iOS 开发者工具推荐,构建从调试到性能优化的多维度生产力工具链(2025 深度工程向)
android·ios·性能优化·小程序·uni-app·iphone·webview
Chrison_mu1 小时前
Android项目背景动效-Kotlin
android·开发语言·kotlin
曾经的三心草3 小时前
JavaEE初阶-多线程2
android·java·java-ee
v***5653 小时前
Spring Cloud Gateway
android·前端·后端
苦逼的搬砖工5 小时前
基于 easy_rxdart 的轻量响应式与状态管理架构实践
android·flutter
2501_915918415 小时前
苹果上架 iOS 应用的工程实践,一次从零到上线的完整记录
android·ios·小程序·https·uni-app·iphone·webview
從南走到北6 小时前
JAVA国际版同城跑腿源码快递代取帮买帮送同城服务源码支持Android+IOS+H5
android·java·ios·微信小程序
2501_915918417 小时前
如何解析iOS崩溃日志:从获取到符号化分析
android·ios·小程序·https·uni-app·iphone·webview
Entropless8 小时前
OkHttp 深度解析(一) : 从一次完整请求看 OkHttp 整体架构
android·okhttp
v***91308 小时前
Spring+Quartz实现定时任务的配置方法
android·前端·后端