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,随机颜色,随机大小

相关推荐
雨白3 小时前
Android 消息机制剖析:从 Handler 投递到 Looper 循环的全链路
android
GY-934 小时前
【Android】数据分层和依赖注入
android
传奇开心果编程5 小时前
【Jetpack Compose娓娓道来】第44课:持久化——让数据“关掉App也不丢”
android·kotlin·移动开发·数据持久化·jetpack compose·ui框架·声明式ui
星空孤辰5 小时前
【camera 008】android camera id 注册、状态监控等状态变化 全流程梳理
android·windows
恋猫de小郭7 小时前
iOS for Web ,把原生 iOS App 跑到进浏览器里面,倒反天罡
android·前端·ios
思想觉悟8 小时前
Android启动流程之点rc文件
android·linux·面试
_祝你今天愉快18 小时前
Android 高级绘制:[四] Canvas-实际案例操作
android
三少爷的鞋19 小时前
Android 工程师的技术信仰崩塌史
android
AirDroid_cn21 小时前
Android 15 权限回溯:已授予的麦克风权限如何批量回收?
android
Mr_万能胶1 天前
官方发布,不烧心的 AOSP 编译提速技巧
android·ci/cd·架构