Search code examples
androidviewviewgroup

Passing the onTouch() event to the underlying ViewGroup


If I have several ViewGroups overlap each other. Is it possible to pass the onTouch() event of a ViewGroup to the underlying ViewGroup?

Each ViewGroup contains Views. But if a touch occurs in an area of a ViewGroup where no View that it contains occupies it, I would like to pass that onTouch() event to the next underlying ViewGroup which also contains Views.


Solution

  • As per I understand your question,

    The main ViewGroup consume the touch event first, in that case,

    Just inflate your layout and make a View..

    then using that view define which view you have to use and setOnTouch().. to that view..

    For example:

    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.xmllayout, null);
    ImageView image_view = (ImageView) view.findViewById(R.id.imagView);
    
    image_view.setOnTouchListener(new OnTouchListener()
                    {
        @Override
        public boolean onTouch(View v, MotionEvent event)
        {
            // TODO Auto-generated method stub
        return false;
        }
    });