我的网页 View 显示良好,没有任何问题。但是,在我应用“选定文本”功能后,网页 View 仅显示在屏幕的一半上(参见下图)。
这是我的代码:
@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/