2012-12-02 65 views
1

我的網絡視圖顯示正常,沒有任何問題。但是,在應用「選定文本」功能後,Web視圖僅顯示在屏幕的一半上(請參閱下圖)。僅在半屏上顯示Android WebView

enter image description here

這裏是我的代碼:

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.content); 

    Intent i = this.getIntent(); 

    final int wordId = i.getIntExtra("id", -1); 
    mCurrentWord = i.getStringExtra("word"); 
    mSelectedDB = i.getStringExtra("db"); 
    mContentStyle = i.getStringExtra("style"); 

    prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); 

    loadHistoryFromPreferences(); 
    loadFavouriteFromPreferences(); 

    wvContent = (WebView) findViewById(R.id.wvContent); 
    initWebview(); 
    String content = getContentById(wordId); 
    showContent(content); 

    //This is the beginning of what I added 
    webkit=new Webkit(this); 
    wvContent.addView(webkit); 
    WebkitSelectedText webkitSelectedText=new WebkitSelectedText(getApplicationContext(), webkit); 
    webkitSelectedText.init(); 

    wvContent.setOnClickListener(new View.OnClickListener() {   
     @Override 
     public void onClick(View v) { 
      finish(); 
     } 
    }); 
    //This is the end of what I added 

我不知道我錯完成。除了這個顯示問題,所有其他功能,包括新增加的一個Selected text工作得很好。

我希望你們能認識到這個問題,幫我修理一下。非常感謝你。

EDITED

這裏是佈局:

<?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" 
android:orientation="vertical" 
android:gravity="bottom|fill_vertical" 
> 
    <LinearLayout xmlns:android= 
    "http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:scrollbars="vertical" 
    android:layout_weight="1" 
    >  
    <WebView 
     android:id="@+id/wvContent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_gravity="top" 
     android:layout_weight="1" 
    /> 

</LinearLayout> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:orientation="horizontal" 
> 
    <ImageButton 
     android:id="@+id/btnHome" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:src="@drawable/home" 
     android:layout_weight="0.25" 
    /> 
    <ImageButton 
     android:id="@+id/btnPronounce" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:src="@drawable/pronounce" 
     android:layout_weight="0.25" 
    />  
    <ImageButton 
     android:id="@+id/btnShowHistory" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:src="@drawable/history" 
     android:layout_weight="0.25" 
    /> 
    <ImageButton 
     android:id="@+id/btnAddFavourite" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:src="@drawable/add_favourite" 
     android:layout_weight="0.25" 
    /> 
</LinearLayout> 

回答

0

該問題可能是與佈局。

在res/layout的content.xml中,確保將webview的android:layout_height的屬性設置爲fill_parent。

這應該修復。不是,也可以粘貼布局的內容。我們可以幫助

+0

謝謝,我已經將它們設置爲「fill_parent」。但請看看我在EDITED中的佈局。 –

+0

請粘貼content.xml的代碼 – nithinreddy

+0

那麼,有人找出問題嗎?請看看幫助。 –

0

我不知道這是否可以幫助有類似的問題或沒有的傢伙,但最終我通過改變解決我的問題:

wvContent.addView(webkit); 

wvContent.addView(webkit,0,0); 

也許不是一個真正的解決方案,而是一種解決方法。

0

我得到了同樣的問題,並認爲我在WebViewClient下面的代碼固定它:

webView.setVisibility(View.VISIBLE); 

我的問題是,它僅在第一次加載顯示半屏,只要我點擊了一個菜單或更改設備的方向,視圖以全屏重新繪製。設置爲可見似乎會觸發重新繪製修復