当Fragment的栈里面有几个fragment的时候,这个时候如果是几个fragment状态是hide,当你触摸当前fragment的时候,下层的fragment的事件被触发,这是由于Touch事件泄露传到了下层中。解决方法就是拦截fragment的
public class YouHuiCategoryFragment extends Fragment implements OnTouchListener {
public YouHuiCategoryFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View ret = inflater.inflate(R.layout.fragment_you_hui_category, container, false);
ret.setOnTouchListener(this);
return ret;
}
// onTouch事件 将上层的触摸事件拦截
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
}