我在scrollView中设置了一个webView。当我最初向下滚动到屏幕底部并在webView中点击链接时,加载的页面会显示在页面中间。如何自动滚动到scrollView的顶部?我已经搜索过,但没有找到答案。iOS会自动执行此操作,但据我所见,Android不会。非常感谢您的帮助和建议。我设置了smoothscroll(0,0),但它会在移动到下一页之前滚动到顶部。也许这是我能使用的全部内容。如果有其他解决方案,将不胜感激。
if(isConnectingToInternet()){
WebProducts.setVisibility(View.VISIBLE);
TextNoInternet.setVisibility(View.GONE);
WebProducts.getSettings().setLoadWithOverviewMode(true);
WebProducts.getSettings().setUseWideViewPort(true);
WebProducts.getSettings().setSupportZoom(false);
WebProducts.loadUrl("http://www.healthfitnessenergy.com/productpages/products.php");
}
else{
WebProducts.setVisibility(View.GONE);
TextNoInternet.setVisibility(View.VISIBLE);
}
WebProducts.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
ScrollView1.smoothScrollTo(0,0);
return false;
}
});
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="30dp"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical" >
<TextView
android:id="@+id/products_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="8dp"
android:gravity="center_vertical"
android:text="@string/product_qs2_products"
style="@style/Bold_Black_20" />
<WebView
android:id="@+id/wvProducts"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="@drawable/gradient_background"
android:orientation="vertical" >
</WebView>
<TextView
android:id="@+id/ifnointernet"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="25dp"
android:gravity="center_vertical"
android:text="Product Menu will be available when cell/wifi service is available"
android:textColor="#333333"
android:textSize="18sp"
android:textStyle="bold"
android:visibility="gone" />
</LinearLayout>