How to scroll to top of long ScrollView layout?

前端 未结 15 781
轻奢々
轻奢々 2020-11-30 18:34

For part of my app, the user is presented with a list of names and is asked to group them as they see fit.

(Note, the ListView code was copied verbatim from the And

相关标签:
15条回答
  • 2020-11-30 18:35

    scrollViewObject.fullScroll(ScrollView.FOCUS_UP) this works fine, but only the problem with this line is that, when data is populating in scrollViewObject, has been called immediately. You have to wait for some milliseconds until data is populated. Try this code:

    scrollViewObject.postDelayed(new Runnable() {
        @Override
        public void run() {
            scroll.fullScroll(ScrollView.FOCUS_UP);
        }
    }, 600);
    

    OR

     scrollViewObject.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            scrollViewObject.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            scrollViewObject.fullScroll(View.FOCUS_UP);
        }
    });
    
    0 讨论(0)
  • 2020-11-30 18:39
     final ScrollView scrollview = (ScrollView)findViewById(R.id.selected_place_layout_scrollview);
    
             scrollview.post(new Runnable() { 
                    public void run() { 
                        scrollview.scrollTo(0, 0); 
                    } 
                }); 
    
    0 讨论(0)
  • 2020-11-30 18:39
    @SuppressWarnings({ "deprecation", "unchecked" })
    public void swipeTopToBottom(AppiumDriver<MobileElement> driver) 
                        throws InterruptedException {
           Dimension dimensions = driver.manage().window().getSize();
            Double screenHeightStart = dimensions.getHeight() * 0.30;
            int scrollStart = screenHeightStart.intValue();
            System.out.println("s="+scrollStart);
            Double screenHeightEnd = dimensions.getHeight()*0.90;
            int scrollEnd = screenHeightEnd.intValue();
            driver.swipe(0,scrollStart,0,scrollEnd,2000);
            CommonUtils.threadWait(driver, 3000);
        }
    
    0 讨论(0)
  • 2020-11-30 18:46

    Had the same issue, probably some kind of bug.

    Even the fullScroll(ScrollView.FOCUS_UP) from the other answer didn't work.
    Only thing that worked for me was calling scroll_view.smoothScrollTo(0,0) right after the dialog is shown.

    0 讨论(0)
  • 2020-11-30 18:46

    I fixed my issue in Kotlin like this:

    scrollview.isFocusableInTouchMode = true
    scrollview.fullScroll(View.FOCUS_UP)
    scrollview.smoothScrollTo(0,0)
    
    0 讨论(0)
  • 2020-11-30 18:47

    This is worked for me

    scroll_view.smoothScrollTo(0,0); // scroll to top of screen
    
    0 讨论(0)
提交回复
热议问题