简体   繁体   English

仅当 EditText 聚焦在滚动视图内时如何使它可滚动(Kotlin)

[英]How to make EditText Scrollable only when it is focused inside a scroll view (Kotlin)

我在 ScrollView 中有一个可滚动的 EditText,即使触摸在 EditText 上(未聚焦),我也想滚动 ScrollView,并且仅在聚焦时才使 EditText 滚动,如果需要,我可以写更多解释

I found the solution, maybe it will help someone else CODE SOLUTION:我找到了解决方案,也许它会帮助其他人代码解决方案:

@SuppressLint("ClickableViewAccessibility")
    private fun addScrollToEditText() {
        binding.cardYourMessageText.setOnTouchListener(OnTouchListener { v, event ->
            if (binding.cardYourMessageText.hasFocus()) {
                v.parent.requestDisallowInterceptTouchEvent(true)
                when (event.action and MotionEvent.ACTION_MASK) {
                    MotionEvent.ACTION_SCROLL -> {
                        v.parent.requestDisallowInterceptTouchEvent(false)
                        return@OnTouchListener true
                    }
                }
            }
            false
        })
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使EditText在可滚动的LinearLayout中可滚动? - How to make an EditText scrollable inside a scrollable LinearLayout? 如何使包裹在另一个滚动视图中的“编辑文本可滚动”? - How to make an Edit Text Scrollable that is wrapped inside another scroll view? 创建Activity时如何使EditText不聚焦 - How to make EditText not focused when creating Activity Android:使多行编辑文本可滚动,在垂直滚动视图中禁用 - Android: Make multiline edittext scrollable, disable in vertical scroll view 如何滚动到 RecyclerView 视图中的 EditText 并将其聚焦? - How to scroll to and focus an EditText inside a view in RecyclerView? 聚焦editText并打开键盘时如何移动视图? - How to move view when editText is focused and keyboard is open? 如何使EditText触发父视图滚动? - How to make EditText trigger parent view scroll? 如何使用requestChildFocus平滑滚动到聚焦的视图? - How to make smooth scroll to the view focused using requestChildFocus? 当EditText聚焦时,Android EditText的容器(RecyclerView)自动滚动 - Android EditText's container (RecyclerView) auto scroll when EditText is Focused 如何使 Android 中的编辑文本可滚动? - How to make edittext in Android scrollable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM