Why does my android activity always start scrolled to the bottom?

前端 未结 11 921
萌比男神i
萌比男神i 2020-12-22 20:56

Whenever I start this activity, it always starts bottomed out--scrolled all the way to the bottom. I am not doing anything weird in the activity OnCreate (or anywhere for th

相关标签:
11条回答
  • 2020-12-22 21:10

    Add these two lines in your ScrollView

     android:focusableInTouchMode="true"
     android:descendantFocusability="blocksDescendants"
    
    0 讨论(0)
  • 2020-12-22 21:10

    I don't know why but you could experiment with

    ScrollView sv = (ScrollView) findViewById(R.id.scroll);
    sv.scrollTo(0,0);
    

    in your onCreate to manually scroll it to where you like it to be.

    0 讨论(0)
  • 2020-12-22 21:11

    Along with what devmiles.com said.

    If you set the following property in your LinearLayout - android:focusableInTouchMode="true" your LinearLayout will be focused on start and your activity won't scroll to EditText in the bottom.

    If you call requestLayout() on a view at the bottom of your linear layout it might steal the focus from your top most view. So just call requestFocus() on the top most view in the linear layout after calling requestLayout() on a lower view.

    0 讨论(0)
  • 2020-12-22 21:17

    You can try this code:

    scroller.post(new Runnable() { 
        public void run() { 
            scroller.fullScroll(ScrollView.FOCUS_DOWN); 
        } 
    }); 
    

    [N:B] [referance link]1

    0 讨论(0)
  • 2020-12-22 21:23

    For Xamarin Android development, if you want to do @Graeme solution then:

    // Set Focus to ScrollView
    ScrollView scrollView = (ScrollView)FindViewById(Resource.Id.scrollView);
    scrollView.FocusableInTouchMode = true;
    scrollView.DescendantFocusability = Android.Views.DescendantFocusability.BeforeDescendants;
    
    0 讨论(0)
提交回复
热议问题