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 V app 冷启动(6) Transition 数据化
android
帅次26 分钟前
Flutter:StatelessWidget vs StatefulWidget 深度解析
android·flutter·ios·小程序·swift·webview·android-studio
好看资源平台1 小时前
安卓逆向环境搭建(Windows/Linux双平台)
android·linux·windows
林奋斗同学2 小时前
Android GMS集成
android
_一条咸鱼_2 小时前
Android Glide 框架线程管理模块原理的源码级别深入分析
android
_一条咸鱼_2 小时前
Android Retrofit 框架注解定义与解析模块深度剖析(一)
android
法欧特斯卡雷特3 小时前
Kotlin Sequence 真的如此不堪吗?
android·后端·编程语言
pengyu3 小时前
系统化掌握Flutter开发之GestureDetector(一):筑基之旅
android·flutter·dart
帅次3 小时前
Flutter Widget 体系结构解析
android·flutter·ios·小程序·xcode·web app·dalvik
罗狮粉 994 小时前
Mysql主从复制和Mysql高可用以及负载均衡配置
android·mysql·负载均衡