2012-05-04 31 views
0

垂直滾動,在我的Android應用我有一個網頁視圖:我不能在網頁視圖

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

<WebView 
    android:id="@+id/webView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

</LinearLayout> 

我的問題是,我不能垂直滾動頁面。水平它工作得很好,但不垂直。現在,如果我將android:layout_height的大小設置爲400dp,那麼它可以工作!但後來我無法支持多種屏幕尺寸......任何想法?

+0

爲什麼不將WebView設置爲'fill_parent'? – Adinia

+0

它不工作 – Alexis

+0

嗯,我使用的是一個RelativeLayout,因爲我需要WebView旁邊的其他元素,但正確的LinearLayout(即與羅馬黑的答案中的方向設置)也應該工作;也許這是你的Java代碼的問題?或者您嘗試打開的HTML頁面?嘗試在你的問題中添加更多的代碼。 – Adinia

回答

2

添加

android:orientation="vertical" 

android:orientation="horizontal" 

到的LinearLayout

+0

它不起作用 – Alexis

+1

它不起作用,因爲LinearLayout不是可滾動佈局。當您將高度和寬度設置爲wrap_content時,webview的邊框超出了LinearLayout的邊界。當您設置佈局方向時,也會將webview的高度和寬度設置爲fill_parent。 –

+0

那麼你會推薦做什麼,我想要什麼? – Alexis

0

也許你可以把webview放在滾動視圖中,通過將高度增加到400 dp,你將它放在創建滾動視圖的線性佈局的限制之外。當頁面加載時,線性佈局不考慮這一點。

+0

我試圖用滾動視圖替換線性佈局 - >沒有工作。我也嘗試通過滾動視圖來包圍線性佈局(包含webview),但它也不起作用。你會怎麼做? – Alexis

1

對我來說,它的工作方式是啓用對web視圖的JavaScript。所以我想如果沒有設置標誌,那麼webkit渲染包含javascript的頁面會出現一些問題。

WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);

+0

很好指出它在我的情況下,啓用JavaScript導致滾動卡住的問題。但禁用它使頁面無用也:( –