无限层级的组织机构
项目中用到的 依照自己的想法做了一个 大家有好的想法来交流一下
项目地址: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 无限极扩展