情景:应用中可滚动内容过多的话,回到顶部需要滚动多次。
实现:直接回到顶部功能。
方案:需要回到顶部的部分写在一个ScrollView内,设置ScollView回到顶部
布局:
<ScrollView
android:id="@+id/sc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/ll_headImg_info" >
代码:
private ScrollView sc;
sc = (ScrollView) findViewById(R.id.sc);
// 让页面返回顶部
sc.post(new Runnable() {
@Override
public void run() {
sc.post(new Runnable() {
public void run() {
// 滚动至顶部
sc.fullScroll(ScrollView.FOCUS_UP);
// 滚动到底部
//sc.fullScroll(ScrollView.FOCUS_DOWN);
}
});
}
});