Coder Social home page Coder Social logo

tree2view's Introduction

Tree2View

TreeView implementation in Android.

数据结构课程设计

主要功能 - Features

TreeView File Explorer
①多级分层的树结构视图 基本的文件管理器布局
②记忆展开状态 自动展开上次打开未关闭的目录
③使用适配器设计模式,用户可自定义 TreeAdapter 对不同类型的文件显示不同的Icon
④动态增删节点 删除和添加文件后可自动刷新状态
⑤选择模式 长按节点进行文件操作(Copy, Cut, Rename, Delete)
⑥动画支持,内置增删节点的动画 增删文件时带有动画

实现原理 - Implement

  • TreeView 继承自 ListView

  • DFS遍历可展开的树节点,转化为List 与 TreeAdapter 进行适配。

  • 分级的视觉效果通过 SimpleTreeAdapter(通过对不同深度的节点设置不同的缩进)来实现的。

  • 使用 DefaultTreeNode 来(用链表保存子节点)增删节点。这样就实现了视觉效果和数据结构统一的设计。

效果预览 - Preview

image

下载 - Download

未上传到 jCenter(),可直接clone本项目使用。

git clone [email protected]:LeeReindeer/Tree2View.git

Then open your project in Android Studio, then Click FIle -> New -> Import Module, to import this module.

And add dependence in your build.gradle

 implementation project(path: ':treeview')

使用 - Usage

Feel free to use it as ListView.

XML:

    <xyz.leezoom.view.treeview.TreeView
        android:id="@+id/tree_view"
        android:layout_marginTop="16dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="#ffffff"
        android:dividerHeight="1px">

    </xyz.leezoom.view.treeview.TreeView>

Kotlin(Java is similar whit it)

  var root :DefaultTreeNode? = DefaultTreeNode("Root")
  val treeView = TreeView(this@MainActivity, root)
  val child1 = DefaultTreeNode("Child1")
  val child2 = DefaultTreeNode("Child2")
  root.addChild(child1)
  root.addChild(child2)
  val child3 = DefaultTreeNode("Child3")
  child1.addChild(child3)

If you want to use customized item view, you should implement TreeAapater, like this:

public class FileTreeAdapter extends TreeAdapter<FileItem> {
  //resourceId is your customized view resourceId, please use RelativeLayout, and let view neighbour.
  public FileTreeAdapter(Context context, DefaultTreeNode root, int resourceId) {
    super(context, root, resourceId);
  }
  
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
     //your code here
     //...
     //call padding for a better UI
     setPadding(holder.arrowIcon, depth, -1);
     //toggle your view's status here
     toggle(node, holder);
    }
    
    @Override
     public void toggle(Object... objects) {
     }

Then simply add:

  val adapter = FileTreeAdapter(this@MainActivity, root, R.layout.layout_file_tree_item)
  treeView.treeAdapter = adapter

License

Apache 2.0

tree2view's People

Watchers

James Cloos avatar  avatar

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.