LazyOrgView
Simply implement the organization chart by customizing View.A search on the web did not find a similar View, and because of the needs of the project, quickly implemented one to meet the needs of the project.Another way to do this: Google OrgChart or other OrgChart.js.
Source Address
Add Dependency
Gradle
Step 1. Add the following to the project root directory build.gradle
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Step 2. Project build.gradle adds dependencies
dependencies {
implementation 'com.github.onlyloveyd:LazyOrgView:v1.0'
}
Basic Use
Step 1. Add LazyOrgView to the layout.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<cn.onlyloveyd.lazyorgview.widget.LazyOrgView
android:id="@+id/rv_content"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
Step 2. Use TreeNode to build node relationships with nodes and other nodes, then use addChildNode to organize node relationships.
TreeNode root = new TreeNode("General manager");
root.isRoot = true;
TreeNode A = new TreeNode("Deputy Manager");
TreeNode Aa = new TreeNode("Administrative Department");
TreeNode Ab = new TreeNode("Finance Department");
TreeNode Ac = new TreeNode("Purchasing Department");
TreeNode B = new TreeNode("Deputy Manager");
TreeNode Ba = new TreeNode("Engineering Department");
TreeNode Bb = new TreeNode("Production Department");
TreeNode C = new TreeNode("Deputy Manager");
TreeNode Ca = new TreeNode("Marketing Department");
TreeNode Cb = new TreeNode("Project Cost Department");
TreeNode Cc = new TreeNode("After sales service");
root.addChildNode(A);
root.addChildNode(B);
root.addChildNode(C);
A.addChildNode(Aa);
A.addChildNode(Ab);
A.addChildNode(Ac);
B.addChildNode(Ba);
B.addChildNode(Bb);
C.addChildNode(Ca);
C.addChildNode(Cb);
Step 3. Configure LazyOrgConfig and rootNode for LazyOrgView.
lazyOrgView.setRootNode(root);
LazyOrgConfig lazyOrgConfig = new LazyOrgConfig();
lazyOrgConfig.setLineColor(Color.BLUE).setTextSize(12)
.setLineWidth(1)
.setTextBgColor(Color.GREEN)
.setTextBgRes(R.drawable.rect_shape);
lazyOrgView.setLazyOrgConfig(lazyOrgConfig);