Is it possible to add a scrollable TextView to a ListView?

后端 未结 4 432
情歌与酒
情歌与酒 2021-01-03 08:24

I have a ListView where each row has a fixed height.
Every row contains, next to some images, a TextView.
Sometimes, the text I want to display is too large and henc

4条回答
  •  滥情空心
    2021-01-03 08:58

    I can make this work by creating a subclass of ListView and override onTouchEvent as follows:
    - I first check whether the MotionEvent is inside a childView
    - if it is, I call the child's onTouchEvent

    This does seem quite basic framework functionality so I'm surprised that this isn't handled by ListView itself. Am I missing something?

        @Override
        public boolean onTouchEvent(MotionEvent event)
        {
            //find correct child
            View theChild = null;
            boolean handled = false;
            for (int i = 0; i < getChildCount(); i++)
            {
                View child = getChildAt(i);
                Rect rect = new Rect();
                child.getDrawingRect(rect);
                offsetDescendantRectToMyCoords(child, rect);
                if(rect.contains((int)event.getX(), (int)event.getY()))
                {
                    theChild = child;
                }
            }
            if(theChild!=null)
            {
                handled = theChild.onTouchEvent(event);
            }
            if(!handled) handled = super.onTouchEvent(event);
    
            return handled;
        }
    

提交回复
热议问题