Что у меня есть:Проблем замещающих андроида фрагмент
Я использую последние поддержки и проектирование библиотеки Android на API 22. У меня есть фрагмент под названием ProgressFragment который я только работать, когда мое приложение впервые установлена следующим образом:
mProgressFragment = new ProgressFragment();
getSupportFragmentManager().beginTransaction()
.replace(R.id.main_container, mProgressFragment, TAG_TASK_FRAGMENT)
.commit();
Это расположение
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/progress_frag"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
>
<ProgressBar
android:id="@+id/build_lib_progressbar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/progress_msg1"
android:layout_gravity="center"
android:textSize="22sp"
android:textColor="@color/text_primary"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/progress_msg2"
android:layout_gravity="center"
android:paddingTop="10dp"
android:textColor="@color/text_secondary"/>
</LinearLayout>
</LinearLayout>
Этот фрагмент содержит AsyncTask. Когда он заканчивает, он заменяется другим фрагментом (так называемый MainFragment) в MainActivity внутри AsyncTask обратного вызова onPostExecute() следующим образом:
getSupportFragmentManager().beginTransaction()
.replace(R.id.main_container, new MainFragment())
.commit();
Это MainFragment макета:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/main_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.AppBarLayout
android:id="@+id/main_appbar_layout"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<include layout="@layout/toolbar" />
<android.support.design.widget.TabLayout
android:id="@+id/main_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"
app:tabIndicatorHeight="4dp"
app:tabTextColor="@color/white"/>
</android.support.design.widget.AppBarLayout>
EDIT:
И это расположение MainActivity в:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Main content displayed here -->
<FrameLayout
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Navigation Drawer -->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_drawer_header"
app:menu="@menu/nav_view_menu"
android:background="#ffffff"
app:itemTextColor="@color/text_tertiary"
app:itemIconTint="#8b8b8b"
/>
Проблема:
Когда AsyncTask в ProgressFragment завершается и заменяется MainFragment, то TabLayout вид не отображает вкладки:
Мое приложение имеет 2 возможных пути при запуске. Это либо:
Добавляет ProgressFragment (если первый запуск) -> заменяется MainFragment
Прибавляет MainFragment в противном случае (вкладки отображаются в порядке здесь)
Оба Фрагментные замены случаются в MainActivity.
Проблема касается пути 1
EDIT 2:
Вызов Recreate() в MainActivity "исправляет" это сейчас. Хотя я бы не назвал это решением. Вернемся к ней позже.
Где ProgressFragment добавляется из ? –
onCreate() в MainActivity. Его макет содержит FrameLayout с идентификатором «main_container», который я заменяю ProgressFragment или MainFragment, в зависимости от того, когда приложение было запущено в первый раз. – user3662681
Пожалуйста, разместите макет MainActivity, а также –