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

后端 未结 4 403
情歌与酒
情歌与酒 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 09:22

    getLineCount and getLineHieght and check if the Text is larger than the TextView.

    if you use this code, the listView can be scrolled by touching anywhere other than the TextView with (boolean)isLarger = true.

    text.setText(s);                
    text.setMaxLines(100);
    text.setVerticalScrollBarEnabled(true);
    text.setMovementMethod(new ScrollingMovementMethod());
    OnTouchListener listener = new OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
                    boolean isLarger;
    
                    isLarger = ((TextView) v).getLineCount()
                            * ((TextView) v).getLineHeight() > v.getHeight();
                    if (event.getAction() == MotionEvent.ACTION_MOVE
                            && isLarger) {
                        v.getParent().requestDisallowInterceptTouchEvent(true);
    
                    } else {
                        v.getParent().requestDisallowInterceptTouchEvent(false);
    
                    }
                    return false;
                }
            };
    
    text.setOnTouchListener(listener);
    

提交回复
热议问题