久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

停止 ScrollView 自動滾動到 EditText

Stop ScrollView from auto-scrolling to an EditText(停止 ScrollView 自動滾動到 EditText)
本文介紹了停止 ScrollView 自動滾動到 EditText的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

似乎是一個常見問題,但我沒有找到很好的解決方案.目標是阻止 ScrollView 自動滾動到具有焦點的 EditText(或任何視圖).

Seems to be a common problem without a great solution that I have found. Goal is to stop a ScrollView from auto-scrolling to an EditText (or any view for that matter) that has focus.

ScrollView 中有一堆視圖(Buttons、TextViews 等),其中一個是 >編輯文本.單擊 ScrollView 中的按鈕后,ScrollView 會向下滾動到 EditText(它的屏幕外).這是不希望的,因為您不希望將其他元素滾動到屏幕之外.

You have a bunch of views (Buttons, TextViews, etc) in an ScrollView, one of which is an EditText. Upon clicking say a Button within the ScrollView, the ScrollView scrolls down to the EditText (its off screen). This is not desired, as there are other elements that you don't want scrolled off the screen.

現在我可以通過在 ScrollView 中添加其他可聚焦元素來阻止在屏幕首次顯示時發生這種情況.但是,普遍的問題仍然存在.用戶手動向下滾動到 EditText,輸入一些數字,然后向上滾動到頂部(EditText 現在離開屏幕),他們單擊 ScrollView 中的按鈕,你猜怎么著?ScrollView 向下滾動到那個該死的 EditText.

Now I can stop this from happening when the screen first shows by having other focusable elements in the ScrollView. However, the general problem still exists. The user scrolls down manually to the EditText, enters some numbers, then scrolls up to the top (EditText off screen now), they click a button in the ScrollView, and guess what? The ScrollView scrolls down to that darn EditText.

我正在考慮擴展 ScrollView 并覆蓋其中的一些方法,例如 findFocusableViewInBounds,但我覺得我只會讓自己陷入更多麻煩.

I'm thinking about extending the ScrollView and overriding some of the methods there like findFocusableViewInBounds, but I have a feeling I'll just be getting myself into more trouble.

如果可以,請提供幫助.

Please help if you can.

我嘗試過在 ScrollView 頂部設置 0 高度 EditText,將 Next Focusable 元素屬性添加到 ScrollView 等.我想一個hack"可能是讓 EditText 在虛擬或手動鍵盤被隱藏或其他情況下失去焦點.

I've played around with things like having an 0 height EditText at the top of my ScrollView, adding Next Focusable element properties to the other items in the ScrollView, etc. I suppose one "hack" might be to get the EditText to lose focus when the virtual or manual keyboard gets hidden or something.

推薦答案

在為這個問題苦苦掙扎了一段時間后,我找到了一個似乎可行而又不會太難看的解決方案.首先,確保任何 ViewGroup(直接)包含您的 EditTextdescendantFocusability 設置為Before Descendants",focusable 設置為true"并且 focusableInTouchMode 設置為true".這將不是 ScrollView 本身,而是您擁有各種視圖的內部布局.接下來添加一個 onTouchListener 到您的 ScrollView 中,當它被觸摸時,它會從 EditText 中移除焦點,如下所示:

After struggling with that problem for quite some time, I've found a solution that seems to work without being too ugly. First, make sure that whatever ViewGroup (directly) contains your EditText has descendantFocusability set to "Before Descendants," focusable set to "true" and focusableInTouchMode set to "true." This will not be the ScrollView itself, but the layout inside where you have your various views. Next add an onTouchListener to your ScrollView that removes focus from the EditText whenever it is touched, like so:

ScrollView scroll = (ScrollView)findViewById(R.id.scrollView1);
scroll.setOnTouchListener(new OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (myEditText.hasFocus()) {
            myEditText.clearFocus();
        }
        return false;
    }
});

如果這不能解決問題,請告訴我.應該發生的是布局而不是 EditText 獲得焦點,因此不應發生滾動.

Tell me if that doesn't fix it. What should happen is that the Layout gets focus instead of the EditText, so no scrolling should happen.

這篇關于停止 ScrollView 自動滾動到 EditText的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event(EditText:禁用文本選擇處理程序單擊事件上的粘貼/替換菜單彈出)
Multiline EditText with Done SoftInput Action Label on 2.3(2.3 上帶有完成 SoftInput 操作標簽的多行 EditText)
How to detect the swipe left or Right in Android?(如何在 Android 中檢測向左或向右滑動?)
Prevent dialog dismissal on screen rotation in Android(防止在Android中的屏幕旋轉對話框解除)
How do I handle ImeOptions#39; done button click?(如何處理 ImeOptions 的完成按鈕點擊?)
How do you set EditText to only accept numeric values in Android?(您如何將 EditText 設置為僅接受 Android 中的數值?)
主站蜘蛛池模板: 日日爱夜夜操 | 亚洲综合精品 | 成人h视频在线 | 中文区中文字幕免费看 | 国产成人99久久亚洲综合精品 | 亚洲欧美一区在线 | 性做久久久久久免费观看欧美 | 国产成人99久久亚洲综合精品 | 国产成人精品视频 | 欧美一区二区精品 | 男女羞羞视频在线观看 | 欧美成人性生活 | 日韩高清在线 | 人人九九 | 成人影院网站ww555久久精品 | 新超碰97 | 久久国产精品一区二区 | 免费一区 | 亚洲精品区 | 欧美a在线 | 国产精品日韩在线 | 91九色网站 | 日本不卡一区二区三区在线观看 | 中文字幕动漫成人 | 91成人在线| 久久久久久久久久久久久9999 | 国产精品久久久久无码av | 欧美一区二区 | 欧美aⅴ| 农夫在线精品视频免费观看 | www.久久 | 操操网站 | 中文字幕视频免费 | 亚洲精品久久久久久久不卡四虎 | 嫩草视频在线看 | 国产一区二区三区四区区 | 欧美白人做受xxxx视频 | 国产精品毛片一区二区三区 | 成人福利在线 | 91新视频| 日韩av网址在线观看 |