Layout작업시에 부모Scroll과 중첩되어 의도된 Child의 Scroll이 안되는 경우가 많습니다.


이럴경우는 안되는 스크롤의 내부 Touch Event를 Override하여 requestDisallowInterceptTouchEvent 메소드를 요청하여 처리하는것이 
일반적입니다.


Webview가 Child일경우 방법은 하단의 2가지입니다.

1.새로운 WebView Class




class CustomWebView : WebView {

    constructor(context: Context) : super(context) {}

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {}

    constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) {}

    override fun onTouchEvent(event: MotionEvent): Boolean {
        requestDisallowInterceptTouchEvent(true)
        return super.onTouchEvent(event)
    }
}


  • 새로운 Class를 활용할경우 Layout Xml에서 Webview에신 해당 Class로 정의를 해줘야 합니다.

<packagename.CustomWebView
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

2.WebView TouchEvent override

이방법은 Activity Class내에 Webview의 TouchListner Interface를 활용하는 방법입니다. 

    webView.setOnTouchListener { v, event ->
        val wv = v as WebView
        wv.requestDisallowInterceptTouchEvent(true)
        return@setOnTouchListener false
    }


+ Recent posts