Android tree control drawing method

preface

As a developer, I come into contact with many excellent software every day. In fact, I have this idea more or less. Can I develop my own software, even office software, hoping to be the text of markdown? Why use office? I often want to make an IDE or something. However, many of them just thought about it and never realized it. I have been in contact with mind mapping software for a long time. At first, I used Microsoft's mind mapping software, then XMIND, and then mindmap Lite. It feels very easy to use. I've also thought about how to implement a mind mapping software. In addition, I pay special attention to the shortcut keys of the software. I often choose the software to see how fast it is, and I don't want the poor shortcut keys. Use mind mapping based on your own practice. A month ago, I implemented a tree like Android control on GitHub, which is actually the beginning of my mind mapping. After implementation, it was found that there were no major obstacles. Let me talk about how I create a tree control. First up effect:

Effect 1

Effect 2

realization

Take the city step by step. Dismember what you want to achieve, what can be achieved? The unknown?

Outline of ideas and steps

The whole structure is divided into: tree, node; The structure of Android includes: model (tree, node), view;

Detailed steps

After seeing the outline of thinking steps, I believe our thinking has been very clear. Does it feel simple? Yes, so does the implementation. When I get here, I start coding. But in order to teach you, I would like to ask you a few questions:

How to traverse the tree? (you can Google, if you have studied data structure, of course, simple) what association is used between nodes and nodes? (next) how to determine the location of a node? What are the rules of location? (??) how to connect two views? (??) ……

In fact, the problem is really a little. But none of this can hinder our pace. We'd better write the known code.

code

1. Node of the tree. Mainly some required data. Parent node, value, child node, whether to focus (for future use), in the tree layer

package com.owant.drawtreeview.model;

import java.util.LinkedList;

/**
 * Created by owant on 16/12/2016.
 */

public class TreeNode<T> {
 /**
  * the parent node,if root node parent node=null;
  */
 public TreeNode<T> parentNode;

 /**
  * the data value
  */
 public T value;

 /**
  * have the child nodes
  */
 public LinkedList<TreeNode<T>> childNodes;

 /**
  * focus tag for the tree add nodes
  */
 public boolean focus;

 /**
  * index of the tree floor
  */
 public int floor;

 public TreeNode(T value) {
  this.value = value;
  this.childNodes = new LinkedList<TreeNode<T>>();

//  this.focus = false;
//  this.parentNode = null;
 }

 public TreeNode<T> getParentNode() {
  return parentNode;
 }

 public void setParentNode(TreeNode<T> parentNode) {
  this.parentNode = parentNode;
 }

 public T getValue() {
  return value;
 }

 public void setValue(T value) {
  this.value = value;
 }

 public LinkedList<TreeNode<T>> getChildNodes() {
  return childNodes;
 }

 public void setChildNodes(LinkedList<TreeNode<T>> childNodes) {
  this.childNodes = childNodes;
 }

 public boolean isFocus() {
  return focus;
 }

 public void setFocus(boolean focus) {
  this.focus = focus;
 }

 public int getFloor() {
  return floor;
 }

 public void setFloor(int floor) {
  this.floor = floor;
 }
}



The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>