我在滚动视图中设置了一个 webview。当我最初向下滚动到屏幕底部并单击 web 视图内的链接时,加载的页面在页面中间可见。如何自动滚动到滚动视图的顶部。我用谷歌搜索但没有答案。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>