В нашем приложении мы используем CoordinatorLayout с двумя панелями инструментов (сверху и снизу), которые выходят из поля зрения при прокрутке. Между панелями инструментов у нас есть FrameLayout, который используется для хранения фрагмента. В настоящее время мы используем в основном один фрагмент, который содержит NestedWebView (https://github.com/takahirom/webview-in-coordinatorlayout). Мы добавляем фрагмент во время выполнения, вызывая метод фрагментации.replace().Фрагмент в FrameLayout в координатореLayout мерцает, когда FrameLayout имеет LayoutBehavior
Проблема в том, что FrameLayout, по-видимому, часто просто исчезает. Иногда он исчезает прямо из приложения, иногда он исчезает, когда я нажимаю кнопки на верхней панели инструментов. Когда он исчезнет, я могу заставить его появиться, повернув телефон или прокрутив верхнюю панель инструментов. Я раскрасил координаторLayout для целей отладки, и я ясно вижу, что иногда WebView заполняет пространство по назначению, но часто WebView невидим.
я понял, что проблема не возникает, когда я удалить
приложение: layout_behavior = "@ строку/appbar_scrolling_view_behavior"
из FrameLayout. Но, конечно, прокрутка не работает так, как предполагалось. Может быть, его стоит отметить, что наш фрагмент имеет
setRetainInstance (истина)
набор. Может кто-нибудь сказать мне, как я могу это исправить? Вот файлы:
CoordinatorLayout XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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=".activity.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/content_container"
android:layout_width="fill_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:theme="@style/AppTheme.AppBarOverlay"
app:layout_behavior=".ui.BottomBarBehavior">
<android.support.v7.widget.ActionMenuView
android:id="@+id/toolbar2"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
WebViewFragment XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/content_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.dfa.diaspora_android.ui.ContextMenuWebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"/>
<ProgressBar
android:id="@+id/progressBar"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:indeterminate="false"
android:layout_height="wrap_content"
android:layout_marginTop="-7dp" />
</RelativeLayout>
Некоторые код от нашего MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main__activity);
ButterKnife.bind(this);
setSupportActionBar(toolbarTop);
MenuInflater menuInflater = getMenuInflater();
Menu bottomMenu = toolbarBottom.getMenu();
menuInflater.inflate(R.menu.main__menu_bottom, bottomMenu);
toolbarBottom.setOnMenuItemClickListener(new ActionMenuView.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
return MainActivity.this.onOptionsItemSelected(item);
}
});
setupUI(savedInstanceState);
}
private void setupUI(Bundle savedInstanceState) {
...
showFragment(StreamFragment.FRAGMENT_NAME);
...
handleIntent(getIntent());
}
private void showFragment(String tag) {
FragmentManager fm = getSupportFragmentManager();
CustomFragment fragment = (CustomFragment) fm.findFragmentByTag(tag);
if (fragment == null) {
switch (tag) {
case StreamFragment.FRAGMENT_NAME:
Log.d(App.TAG, "Create new StreamFragment");
fragment = new StreamFragment();
break;
default:
Log.e(App.TAG, "Missing fragment "+tag+" in showFragment switch case...");
return;
}
}
currentFragment = fragment;
if (!fragment.isVisible()) {
Log.d(App.TAG, "Fragment not visible. Replace it");
fm.beginTransaction().replace(R.id.content_container, fragment, tag).commit();
//Add fragment's bottom menu entries
currentFragment.onCreateBottomOptionsMenu(toolbarBottom.getMenu(), getMenuInflater());
} else {
Log.d(App.TAG, "Fragment was visible");
}
}
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
// Reinitialize the UI
setupUI(null);
}
Я сообщил об этой ошибке в поисковом журнале googles: https://code.google.com/p/android/issues/detail?id=222993 –