2012-12-02 66 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); 

我的问题是,它仅在第一次加载显示半屏,只要我点击了一个菜单或更改设备的方向,视图以全屏重新绘制。设置为可见似乎会触发重新绘制修复