TextView ScrollingMovementMethod 在ScrollView中滑动冲突

来源:互联网 发布:知乎 户外保暖帽子 编辑:程序博客网 时间:2024/04/30 10:00

好记性不如烂笔头

当textview现在高度,但是内容比较多时就需要滑动

 tvChannel1.setMovementMethod(ScrollingMovementMethod.getInstance());

但是如果外层有ScrollView 会导致滑动失效

解决办法,集成textview重写方法

public class ScrollTextView extends TextView {    public ScrollTextView(Context context) {        super(context);    }    public ScrollTextView(Context context, AttributeSet attrs) {        super(context, attrs);    }    public ScrollTextView(Context context, AttributeSet attrs, int defStyleAttr) {        super(context, attrs, defStyleAttr);    }    @Override    public boolean onTouchEvent(MotionEvent event) {        getParent().requestDisallowInterceptTouchEvent(true);//处理父控件拦截事件        return super.onTouchEvent(event);    }}


0 0