当ScrollView为根布局时,若嵌入ListView或GridView,就会出现不是从顶部开始显示的情况。我们只需要对ScrollView的顶部View设置几个属性就可以了。
xml代码:
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
>
<requestFocus/>
</View>
java代码:
view.setFocusable(true);
view.setFocusableInTouchMode(true);
view.requestFocus();