Приложение изменяет текст на reviewer_flashcard
при нажатии. Я хочу, чтобы Google Translate показывал фрагмент между изменениями, а не всю активность (я выбрал WebView
). В первый раз все идет по правильному пути, а после - нет. Я думаю, что когда фрагмент создает, он имеет более высокий приоритет уровня, при обновлении других фрагментов перекрывает его.
Как нанести WebView
на верхний слой?
Я пытался использовать getSupportFragmentManager().beginTransaction().replace(fragment1, fragment2)
, но он требует двух фрагментов (WebView
нет), и я столкнулся с проблемой, что он не работает с фрагментами на основе XML.
Кроме того, я нашел это решение, но я не могу его получить
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());
}