java - Android WebView仅显示在半屏上

标签 java android android-layout android-webview

我的网页 View 显示良好,没有任何问题。但是,在我应用“选定文本”功能后,网页 View 仅显示在屏幕的一半上(参见下图)。

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都工作得很好。

我希望你们能意识到这个问题并帮我解决它。非常感谢。

已编辑

这是布局:

<?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>   

最佳答案

问题可能出在布局上。

在 res/layout 的 content.xml 中,确保将 webview 的 android:layout_height 属性设置为 fill_parent。

这应该可以解决。不行,把布局的内容也粘贴一下。我们可以提供帮助

关于java - Android WebView仅显示在半屏上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13670683/

相关文章:

java - 为什么 ExecutorService.invokeAll() 会返回一个 Future 列表?

android - 错误 : Plugin with id 'com.google.firebase:firebase-auth:9.2.0' not found

android - 为什么 Android 模拟器忽略我的 list 权限?

android - 如何知道我是否应该在布局中使用 ldpi

java - eclipse 在我的项目旁边显示感叹号

java - HP QTP (VbScript) : work with Java-objects (like DotNetFactory for . NET 类)

java - 通过Java在管理员中执行CMD

java - 无法删除或更新双向关系中的父行

android - 带有 edittext 的 DialogFragment 在解雇后不会丢失键盘

android - 支持多种屏幕分辨率的应用程序