Code Monkey home page Code Monkey logo

android-thinkmap-treeview's Introduction

GysoTreeView

中文】【English⭐If ok, give me a star⭐

⭐⭐⭐⭐⭐Tree View; Mind map; Think map; tree map; 树状图;思维导图;组织机构图;层次图;树型图

A custom tree view for Android, designed for easy drawing some tree nodes (e.g. thind mind and tree nodes). Includes smoothly zoom, move, limit and center fix animation support, and allows easy extension so you can add your own child node's customs view and touch event detection.

    dependencies {
//请直接使用lib中的代码,1.0.0这个引用库很久没有更新了
    	implementation 'androidx.dynamicanimation:dynamicanimation:1.0.0'
   	implementation 'io.github.guaishoun:gyso-treeview:1.0.1'
   }

Funtions

  • 🍇Smoothly zoom, move
  • 🍈Fix your window view port
  • 🍉Custom your subview for special node
  • 🍊Custom lines between nodes
  • 🍋Dynamic remove nodes
  • 🍌Dynamic add nodes
  • 🥭Drag to rebuild the nodes' relationship

Releases & downloads

Base--Line, LayoutManger, Custom node view

Add

Remove

Drag Edit Mode

Click

Zoom and Fit Window

Steps for use

    <com.gyso.treeview.GysoTreeView
        android:id="@+id/base_tree_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorBackground">
    </com.gyso.treeview.GysoTreeView>

Before presentation, Animal class means you own bean class, like this:

public class Animal {
    public int headId;
    public String name;
}

To use a tree view, you should do 5 steps as follows:

  1. Customs adapter by extends TreeViewAdapter.

    public class AnimalTreeViewAdapter extends TreeViewAdapter<Animal> {
        private DashLine dashLine =  new DashLine(Color.parseColor("#F06292"),6);
        @Override
        public TreeViewHolder<Animal> onCreateViewHolder(@NonNull ViewGroup viewGroup, NodeModel<Animal> node) {
            //TODO in inflate item view
            NodeBaseLayoutBinding nodeBinding = NodeBaseLayoutBinding.inflate(LayoutInflater.from(viewGroup.getContext()),viewGroup,false);
            return new TreeViewHolder<>(nodeBinding.getRoot(),node);
        }
    
        @Override
        public void onBindViewHolder(@NonNull TreeViewHolder<Animal> holder) {
            //TODO get view and node from holder, and then control your item view
            View itemView = holder.getView();
            NodeModel<Animal> node = holder.getNode();
    		...
        }
    
        @Override
        public Baseline onDrawLine(DrawInfo drawInfo) {
            // TODO If you return an BaseLine, line will be draw by the return one instead of TreeViewLayoutManager's
    		// if(...){
            //   ...
            // 	 return dashLine;
       		// }
            return null;
        }
    }
  2. configure layout manager. Space unit is dp. You can custom you line by extends {@link com.gyso.treeview.line.BaseLine}

    int space_50dp = 50;
    int space_20dp = 20;
    //choose a demo line or a customs line. StraightLine, PointedLine, DashLine, SmoothLine are available.
    Baseline line =  new DashLine(Color.parseColor("#4DB6AC"),8);
    //choose layoout manager. VerticalTreeLayoutManager,RightTreeLayoutManager are available.
    TreeLayoutManager treeLayoutManager = new BoxRightTreeLayoutManager(this,space_50dp,space_20dp,line);
    
     // TODO Other stable layout managers like below:
     // new BoxDownTreeLayoutManager(this,space_50dp,space_20dp,line);
     // new BoxLeftTreeLayoutManager(this,space_50dp,space_20dp,line);
     // new BoxUpTreeLayoutManager(this,space_50dp,space_20dp,line);
     // new BoxHorizonLeftAndRightLayoutManager(this,space_50dp,space_20dp,line);
     // new BoxVerticalUpAndDownLayoutManager(this,space_50dp,space_20dp,line);
  3. setting adapter and layout manager for your tree view.

    ...
    treeView = findViewById(R.id.tree_view);   
    TreeViewAdapter adapter = new AnimlTreeViewAdapter();
    treeView.setAdapter(adapter);
    treeView.setTreeLayoutManager(treeLayoutManager);
    ...
  4. nodes data setting

    //Create a TreeModel by using a root node.
    NodeModel<Animal> node0 = new NodeModel<>(new Animal(R.drawable.ic_01,"root"));
    TreeModel<Animal> treeModel = new TreeModel<>(node0);
    
    //Other nodes.
    NodeModel<Animal> node1 = new NodeModel<>(new Animal(R.drawable.ic_02,"sub0"));
    NodeModel<Animal> node2 = new NodeModel<>(new Animal(R.drawable.ic_03,"sub1"));
    NodeModel<Animal> node3 = new NodeModel<>(new Animal(R.drawable.ic_04,"sub2"));
    NodeModel<Animal> node4 = new NodeModel<>(new Animal(R.drawable.ic_05,"sub3"));
    NodeModel<Animal> node5 = new NodeModel<>(new Animal(R.drawable.ic_06,"sub4"));
    
    
    //Build the relationship between parent node and childs,like:
    //treeModel.add(parent, child1, child2, ...., childN);
    treeModel.add(node0, node1, node2);
    treeModel.add(node1, node3, node4);
    treeModel.add(node2, node5);
    
    //finally set this treeModel to the adapter
    adapter.setTreeModel(treeModel);
  5. If your want to edit your tree view, please use an editor.

final TreeViewEditor editor = binding.baseTreeView.getEditor();

//add nodes
NodeModel<Animal> a = new NodeModel<>(new Animal(R.drawable.ic_13,"add-" + atomicInteger.getAndIncrement()));
NodeModel<Animal> b = new NodeModel<>(new Animal(R.drawable.ic_10,"add-" + atomicInteger.getAndIncrement()));
NodeModel<Animal> c = new NodeModel<>(new Animal(R.drawable.ic_11,"add-" + atomicInteger.getAndIncrement()));
editor.addChildNodes(targetNode,a,b,c);

//remove node
editor.removeNode(toRemoveNode);

//view center in window viewport
editor.focusMidLocation()
    
//drag to move and build new relationship
editor.requestMoveNodeByDragging(isChecked);

Notes & limitations

Firstly, only vertical-down derection layout and right direction layout is available, more layout style should be code.

Secondly, customing lines by extends BaseLine may be a little complicate for Android beginner, and performance issues will happen if you using carefully.

Finally, this custom view will be continuely improved, if you has some innovative ideas, please tell me. Thanks for you patience.

I will tell you how it works on my CSDN blogs.Thx.

android-thinkmap-treeview's People

Contributors

guaishoun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-thinkmap-treeview's Issues

作者有遇见会让studio的xml卡顿吗?

起初我以为是项目的问题。
然后创建了一个全新的项目,这时候去写布局,xml会非常快,无感提示。
但是一旦添加进入导图的这个library,主moudle还未依赖,就导致studio的主moudle中写xml布局很卡顿。几秒才提示。
然后我继续测试,在setting.gradle中只要不include这个项目,就很正常。一导入就不行。
重启电脑,重启studio,清理缓存,重传studio。在一个纯净电脑上新装studio都试过了。都会卡顿。
作者大大猜测有可能什么原因导致的?

删除节点

请问怎么删除父节点下的所有子节点,同时不要删除父节点?现在项目里的代码是删除一个父节点后把子节点和当前节点都删了,所有我通过遍历每个子节点进行删除,但是在不使用删除节点动画时可以通过便利删除每个节点(虽然可以实现删除功能但是删除后视图会抖动偏移),而当设置删除动画为true时节点会出现删不掉的bu g

版本问题

作者非常感谢,你的库我现在正好需要,我下载了你的demo,我看到引用的时候你说1.0.0这个版本没有更新了,但是我看到library中也是1.0.0 我看到你的分支有1,1 1.2 2.0具体是使用那个呢?

数据无法保存

请问数据改如何序列化成json数据存储起来呢?使用Gson序列化直接报错

ios equavilent

Hi, thanks for very useful library. Do u support ios version? THanks

节点创建位置错误

横竖屏时,添加新节点时位置错误,如果当前画布高度小内容超出屏幕,直接拉到屏幕中间断开上个节点了

位置重叠

6d033d97-1838-44c7-a40d-cce2e0166de4
使用CompactRingTreeLayoutManager,数据只有一层关系时,第一条数据会和最后一条叠加在一起

感谢作者!目前Android方面最好的导图框架了。

感谢作者大大的开源内容。
我在此基础上实现了多root的脑图
线条的更新(实现节点走过的效果,就像游戏上的技能图一样。)
....
其他小实现。
本来年中的时候就想着pr。但是太忙了,后续也不想弄了。但是还想帮助这个框架更完善。
有哪个朋友乐意或者有脑图需求,可随时call。我详细说明实现。
v XQL8686

关于节点的收起和展开功能

请问作者有实现点击节点展开和收回其子节点的功能吗?
如果有该如何使用?
如果没有能提供下思路嘛?非常感谢

只有VerticalTreeLayoutManager与RightTreeLayoutManager两种布局

implementation 'io.github.guaishoun:gyso-treeview:1.0.1'
只有VerticalTreeLayoutManager 和 RightTreeLayoutManager 两种布局方式

下载的里面却有好多种布局
RightTreeLayoutManager
LeftTreeLayoutManager
CompactRightTreeLayoutManager
CompactLeftTreeLayoutManager
…………………………

Help with a couple questions

Hello, I have been reviewing your library for an upcoming project and it is amazing!

I have a couple questions;

Is it possible to add a termination for the line, like an arrow?

Is it possible to make lines clickable?

I need to be able to create nodes with multiple parents. I have looked through your tree model, have you thought about using a DAG (Directed Acyclic Graph) for the model to allow for a multi-parent approach?
https://www.baeldung.com/cs/dag-applications
If you haven't could you point me to the location for the draw code and model to modify the structure to a DAG?

Thanks for creating such a great library!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.