如何将WebView放在顶层?

时间:2019-01-11 14:19:56

标签: java android webview

该应用会在点击时更改reviewer_flashcard上的文本。我想展示Google Translate的变化之间的片段,而不是整个活动(我选择了WebView)。第一次,它以正确的方式进行,但之后就不正确了。我认为当片段创建时,它具有更高的层优先级,在更新其他片段时会重叠它。 如何将WebView放在顶层?

我尝试使用getSupportFragmentManager().beginTransaction().replace(fragment1, fragment2),但它需要两个片段(不是WebView),我遇到了一个问题,即它不适用于基于XML的片段。 另外,我找到了this解决方案,但我找不到

reviewer.xml

    <RelativeLayout
        android:id="@+id/front_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <include layout="@layout/toolbar"/>

        <include layout="@layout/reviewer_topbar"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_below="@+id/toolbar" />

        <include layout="@layout/reviewer_flashcard"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

        <WebView
            android:id="@+id/translator_web_view"
            android:clickable="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <include layout="@layout/reviewer_answer_buttons"/>

    </RelativeLayout>

reviewer_flashcard.xml

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_gravity="center"
    android:id="@+id/flashcard_frame"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_margin="0dip">

    <FrameLayout
        android:id="@+id/flashcard"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center">

    </FrameLayout>

    <FrameLayout
        android:layout_gravity="center"
        android:id="@+id/touch_layer"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_margin="0dip"
        android:longClickable="true" />
    <FrameLayout
        android:id="@+id/whiteboard"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:layout_margin="0dip" />
    <ImageView
        android:id="@+id/lookup_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:clickable="true"
        android:padding="5dip"
        android:src="@drawable/ic_lookup"
        android:visibility="gone"
        android:contentDescription="@string/lookup_button_content" />

</FrameLayout>

初始化

protected void initLayout() {
    ...
    translatorWebView = (WebView) findViewById(R.id.translator_web_view);
    translatorWebView.setVisibility(View.INVISIBLE);
    ... }



public void displayGoogleTranslateView(){
    translatorWebView.setVisibility(View.VISIBLE);

    translatorWebView.setVerticalScrollBarEnabled(true);
    translatorWebView.setHorizontalScrollBarEnabled(true);
    translatorWebView.getSettings().setJavaScriptEnabled(true);
    translatorWebView.getSettings().setAppCacheEnabled(true);
    translatorWebView.loadUrl("https://translate.google.com/?hl=en&tab=wT&authuser=0#view=home&op=translate&sl=en&tl=ru&text=" + buildUrlForTranslator(mCurrentCard.qSimple()));;
    translatorWebView.setWebViewClient(new WebViewClient());

}

0 个答案:

没有答案