android scrollable textview inside scrollview

后端 未结 5 1540
無奈伤痛
無奈伤痛 2020-12-17 14:38

i need to create like scrolling TextView inside the ScrollView.. like 1 main ScrollView inside that scrollable TextView i

5条回答
  •  春和景丽
    2020-12-17 15:32

    First, set android:scrollbars="vertical":

    
    

    Also, add this extension function:

    /**
     * If this [AppCompatTextView] is placed inside ScrollView then we allow it get scrolled inside
     * that ScrollView
     */
    fun AppCompatTextView.makeScrollableInsideScrollView() {
        movementMethod = ScrollingMovementMethod()
        setOnTouchListener { v, event ->
            v.parent.requestDisallowInterceptTouchEvent(true)
            when (event.action and MotionEvent.ACTION_MASK) {
                MotionEvent.ACTION_UP -> {
                    v.parent.requestDisallowInterceptTouchEvent(false)
                    //It is required to call performClick() in onTouch event.
                    performClick()
                }
            }
            false
        }
    

    Then call:

    actv.makeScrollableInsideScrollView()
    

提交回复
热议问题