Android ScrollView doesn't start at top, but at the beginning of the GridView

后端 未结 12 2478
天涯浪人
天涯浪人 2020-12-23 11:19

I have a problem with a ScrollView that has inside of it a personalized GridView and other tipe of views.The first time I start the Activity, the ScrollView starts at its to

12条回答
  •  离开以前
    2020-12-23 11:57

    Simple way to achieve this is to set up an ID to your ScrollView in XML ... let's say

    scrollView_main
    

    After that you just need to go to your java file and declare it like a normal variable above the procedure onCreate to be a global one like this

    ScrollView scrollView_main;
    

    ok, now is time to go to onCreate procedure and declare this, to get connection with your ID from XML file

    scrollView_main = (ScrollView)findViewById(R.id.scrollView_main);
    

    and finally the code that will do the trick for your ScrollView to be scrolled on top, this is your answer

    scrollView_main.smoothScrollTo(0,0); //set it on top
    

提交回复
热议问题