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

后端 未结 12 2490
天涯浪人
天涯浪人 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 12:01

    The easiest way is to add on the parent ScrollView the following xml attributes:

    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true"
    

    That means that the ScrollView as a whole will be the one getting focus instead of any inner container when you launch the activity. This is also useful, for example, when you have an edit text inside your layout and you don't want it to get focus immediately and popup the keyboard when entering a screen (It's the same principle).

    So, your ScrollView on top of your layout would look like this:

    
    

提交回复
热议问题