Это должно быть довольно простым, я просто не могу понять, как это сделать. У меня есть webView, который показывает, что страница слишком длинная, чтобы показать все сразу. Сейчас он показывает полосу прокрутки, но на самом деле она не прокручивается. Он просто немного виляет немного, чтобы вы знали, что это активная полоса прокрутки.
Надеюсь, в макете xml, насколько это возможно, я бы хотел, чтобы страница прокручивалась по мере необходимости, чтобы показать всю страницу.
мой файл макета xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<WebView
android:id="@+id/news_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
onСоздать вызов:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.news);
WebView webView = (WebView) findViewById(R.id.news_view);
webView.setVerticalScrollBarEnabled(true);
webView.loadUrl("http://www.example.com/index.html");
}
Вы думали об использовании ScrollView?
<ScrollView android:layout_width="fill_parent"
android:layout_height="86px"
android:id="@+id/scrollTxtDescription"
android:layout_below="@id/txtLieuPromo1"
android:layout_alignLeft="@id/txtLieuPromo1">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/layoutTxtDescription"
>
<WebView android:id="@+id/txtDescription"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</ScrollView>
Я использую следующий код, и он работал у меня (тестировался на Android 2.3 и Android 4.2)
расположение:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<WebView
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</ScrollView>
код:
final WebSettings settings = mWebView.getSettings();
settings.setDomStorageEnabled(true);
settings.setJavaScriptEnabled(true);
mWebView.setVerticalScrollBarEnabled(true);
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
super.shouldOverrideUrlLoading(view, url);
return false;
}
@Override
public void onPageFinished(final WebView view, final String url) {
super.onPageFinished(view, url);
mWebView.requestLayout();
}
});
mWebView.loadUrl(uri);