无限层级的组织机构

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

项目地址: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 无限极扩展

转载于:https://www.cnblogs.com/yxysuanfa/p/7256356.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值