1

Web ビューは問題なく表示されました。ただし、「選択したテキスト」機能を適用した後、Web ビューは画面の半分にしか表示されません (下の画像を参照)。

ここに画像の説明を入力

これが私のコードです:

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

4

3 に答える 3

0

レイアウトに問題がある可能性があります。

res/layout の content.xml で、webview の android:layout_height のプロパティを fill_parent に設定してください。

これで直るはずです。そうじゃなくて、レイアウトの中身も貼り付け。そして、私たちは助けることができます

于 2012-12-02T16:32:34.440 に答える
0

私は同じ問題を抱えていましたが、WebViewClient の次のコードで修正したと思います。

webView.setVisibility(View.VISIBLE);

私の問題は、最初の読み込みで半分の画面しか表示されず、メニューをクリックするか、デバイスの向きを変更するとすぐに、ビューが全画面で再描画されることでした。それを Visible に設定すると、その修正が再描画されるように見えました

于 2014-12-01T21:22:12.133 に答える
0

これが同様の問題を抱えている人に役立つかどうかはわかりませんが、最終的には次のように変更して問題を解決します。

wvContent.addView(webkit);

wvContent.addView(webkit,0,0);

本当の解決策ではありませんが、おそらく回避策です。

于 2013-04-30T10:01:00.877 に答える