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

相关推荐
Ehtan_Zheng2 分钟前
Jetpack Compose 与 RecyclerView 混合布局的性能债
android
Kapaseker1 小时前
MVVM 旧城改造,边界划分各有招
android·kotlin
我滴老baby1 小时前
多智能体协作系统设计当AI学会团队合作效率翻十倍
android·开发语言·人工智能
StockTV1 小时前
新加坡股票API 实时行情、K 线及指数数据
android·java·spring boot·后端·区块链
草莓熊Lotso2 小时前
LangChain从入门到精通:环境搭建→核心能力→LCEL链式编程全实战
android·java·linux·服务器·langchain
私人珍藏库15 小时前
【Android】聆听岛[特殊字符]聚合全网音乐[特殊字符]免费听歌下载神器[特殊字符] 聚合音乐平台|无损母带下载|歌词封面同步|免费无广告听歌工具
android·人工智能·工具·软件·多功能
YF021116 小时前
Android触摸机制与自定义 View 实战
android·app
Dabei16 小时前
Android TV 焦点处理详解:遥控器与空鼠
android·前端
悠哉清闲17 小时前
裁剪SurfaceView
android
常利兵17 小时前
Android字体字重设置全攻略:XML黑科技+Kotlin动态实现,告别.ttf臃肿
android·xml·科技