@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { /** 遍历子view,按group号分组 */ int childcount = this.getChildCount(); for (int i = 0; i < childcount; i++) { View view = this.getChildAt(i); Log.e("GroupSingleTouchTextView", "onmeasure"); if (view instanceof LayoutStyleableInterface) { int group = ((LayoutStyleableInterface) view).getGroup(); /** 未分组状态下,group为-1 */ if (group != -1) { if (view instanceof SelectedTextView) ((SelectedTextView) view).setSingleSelectedInterface(singleSelectedInterface); // ((SelectedTextView)view).setSingleSelectedInterface() ArrayList<LayoutStyleableInterface> list; if (groupMap.containsKey(group)) list = groupMap.get(group); else { list = new ArrayList<LayoutStyleableInterface>(); groupMap.put(group, list); } list.add((LayoutStyleableInterface) view); } } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); }
@Override public void setSingleView(LayoutStyleableInterface Ilayout) { int n = 0; ArrayList<LayoutStyleableInterface> list = groupMap.get(Ilayout.getGroup()); for (LayoutStyleableInterface i : list) { n++; // Log.e("GroupSingleTouchTextView", "setSingleView"); if (Ilayout != i && ((SelectedTextView) i).isSelected()) { ((SelectedTextView) i).setNaturalBackground(); } } }