久久久久久久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 中的數值?)
主站蜘蛛池模板: 黄色精品 | 久久aⅴ乱码一区二区三区 91综合网 | 91av在线免费 | 久久精品av麻豆的观看方式 | 一级免费毛片 | 久久久久九九九九 | 亚洲精品一区中文字幕乱码 | 欧美性大战久久久久久久蜜臀 | 国产精品亚洲一区 | 美国一级毛片a | 91婷婷韩国欧美一区二区 | 亚洲精品视频在线 | 久优草| 在线视频h | 国产99久久精品一区二区永久免费 | 欧美第一页 | 在线第一页 | 久久国产精品首页 | 日本精品一区二区三区视频 | 免费一看一级毛片 | 99色在线| 日本大片在线播放 | 精品久久久久久亚洲精品 | 国产精品国产a | 色视频网站 | 成人免费网站视频 | 美女国产一区 | 国产精品久久久久久婷婷天堂 | 欧美一区二区在线观看视频 | 蜜桃视频在线观看免费视频网站www | 日韩精品一区二区三区在线 | 亚洲综合色视频在线观看 | 国产乱码精品一区二区三区中文 | 亚洲三级在线观看 | 免费视频一区二区 | 91香蕉 | 999精品在线| 欧美淫 | 国产精品久久久免费 | 欧美日韩一区二区在线 | 一区在线播放 |