EditText not scrollable inside ScrollView

前端 未结 11 728
栀梦
栀梦 2020-12-02 12:36

I have a ScrollView inside which is an EditText which is set to scroll vertically. But it does not scrolls. Instead the whole layout scrolls, Whene

11条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 12:44

    XML code

        android:gravity="top"
        android:inputType="text|textMultiLine"
        android:lines="5"
    

    Use below code for Kotlin

        editText.setOnTouchListener { v, event ->
            if (v.id == R.id.editText) {
                v.parent.requestDisallowInterceptTouchEvent(true)
                when (event.action and MotionEvent.ACTION_MASK) {
                    MotionEvent.ACTION_UP -> v.parent.requestDisallowInterceptTouchEvent(false)
                }
            }
            false
        }
    

提交回复
热议问题