I have an expandable list with groups and childrens. Each child is of TableRow class holding image, text and another image. Its width is less than group width which leads to offset before and after child row. The problem is when touching the child, offset area turns to se开发者_开发技巧lected and actual child area stays untouched. I need an opposite effect when only child area being selected.
Ok. Found a solution.
Disabled isChildSelectable:
public boolean isChildSelectable(int groupPosition, int childPosition) { return false; }
Implemented my onTouchListener in getChildView:
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { parent.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); View childView = getMyView(); childView.setOnTouchListener(new OnTouchListener(){ @Override public boolean onTouch(View view, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { view.setBackgroundColor(Color.BLUE); return true; } if (event.getAction() == MotionEvent.ACTION_UP) { view.setBackgroundColor(Color.WHITE); return true; } if (event.getAction() == MotionEvent.ACTION_OUTSIDE) { view.setBackgroundColor(Color.WHITE); return true; } if (event.getAction() == MotionEvent.ACTION_CANCEL) { view.setBackgroundColor(Color.WHITE); return true; } return false; } }); LinearLayout newView = new LinearLayout(context); newView.setPadding(15, 0, 15, 0); newView.addView(childView); return newView; }
精彩评论