• 无限层级的组织机构


    项目中用到的 依照自己的想法做了一个 大家有好的想法来交流一下

    项目地址:https://github.com/caoweiaaa/OrganizationLevel

    效果图:

    层级部分用是自己定义一个LinearLayou 可像里面放入TextView,以下是ExpandableListView 

    LinearLayout中提供一个点击的接口和一个移除点击的位置之后的全部控件

    package com.chs.organizationlevel.wedgit;
    
    import android.content.Context;
    import android.util.AttributeSet;
    import android.view.View;
    import android.widget.LinearLayout;
    
    import com.chs.organizationlevel.R;
    
    /**
     * 作者:chs on 2015/12/31 15:24
     * 邮箱:657083984@qq.com
     */
    public class MyLinearLayout extends LinearLayout {
        private Context mContext;
        private OnItemClickListener onItemClickListener;
        public MyLinearLayout(Context context) {
            super(context);
            mContext = context;
        }
    
        public MyLinearLayout(Context context, AttributeSet attrs) {
            super(context, attrs);
            mContext = context;
        }
       public interface OnItemClickListener{
        void onItemClick(int position);
       }
    
        public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
            this.onItemClickListener = onItemClickListener;
        }
    
        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b) {
            super.onLayout(changed, l, t, r, b);
            final int count = getChildCount();
            for(int i = 0;i<count;i++){
                View view = getChildAt(i);
                if(i>0){
                    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT);
                    layoutParams.setMargins(-40, 0, 0, 0);
                    view.setLayoutParams(layoutParams);
                }
                if((count-i)==1){
                    view.setBackgroundResource(R.mipmap.organization_bg_blue);
                }else {
                    view.setBackgroundResource(R.mipmap.organization_bg_gray);
                }
                final int finalI = i;
                view.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if(count>1&&(count-finalI)!=1){
                            onItemClickListener.onItemClick(finalI);
                        }
                    }
                });
            }
        }
        public void removeView(int position){
            int count = getChildCount();
            int x = 0;
            for(int i = 0;i<count;i++){
                View view = null;
                if(i>position){
                    view = getChildAt(i-x);
                    removeView(view);
                    x++;
                }
            }
        }
    }
    

    数据是后台给的一个json ,项目中能够让后台给传这样的格式的json 无限极扩展


  • 相关阅读:
    Android UI 之实现多级列表TreeView
    python小游戏实现代码
    【iOS知识学习】_UITableView简介
    根据指定电话号码得到通讯录上的姓名
    【转载】公钥、私钥、数字签名等知识
    常见的哈希Hash算法 & MD5 & 对称非对称加密 & 海明码
    Mac电脑解压文件unrar用密码问题解决
    一道题目- Find the smallest range that includes at least one number from each of the k lists
    求逆序对数总结 & 归并排序
    【转载】非常棒的算法面试类资源汇总
  • 原文地址:https://www.cnblogs.com/yxysuanfa/p/7256356.html
Copyright © 2020-2023  润新知