我使用導航抽屜創建了一個應用程序。如果我切換到選項卡,在這種情況下爲WebView
,則WebView
未正確顯示。 Picture (area is marked)未正確顯示WebView
片段:
public class StudentPlanFragment extends Fragment {
private WebView mWebView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_student_plan, null);
mWebView = (WebView) rootView .findViewById(R.id.webViewStudentPlan);
mWebView.loadUrl("http://example.com");
mWebView.getSettings().setJavaScriptEnabled(true);
return rootView ;
}
}
我的XML的文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="de.nichuhn.hlg.StudentPlanFragment"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:id="@+id/constraintLayout">
<WebView
android:layout_width="match_parent"
android:id="@+id/webViewStudentPlan"
tools:layout_editor_absoluteY="0dp"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
檢查我的解決辦法@ N.Preusche –