我面临与折叠工具栏相关的奇怪问题。旋转屏幕时,折叠工具栏会在合同折叠工具栏时隐藏工具栏标题。
折叠工具栏展开时显示工具栏标题
请在此处屏蔽截图:https://imgur.com/a/99msG
<?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"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="@dimen/collapsing_toolbar_title_margin_end"
app:expandedTitleMarginStart="@dimen/collapsing_toolbar_title_margin_start"
app:expandedTitleTextAppearance="@style/CollapsedAppBarTextAppearance"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="@drawable/world_image"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?android:attr/actionBarSize"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/list_countries"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_color"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
Java代码:
public class CountryListFragment extends Fragment {
@BindView(R.id.list_countries)
RecyclerView mCountriesListRecyclerView;
@BindView(R.id.toolbar)
Toolbar mToolbar;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_countries_list, container, false);
//must bind for View Injection
ButterKnife.bind(this, view);
// register event bus to receive events
EventBus.getDefault().register(this);
((AppCompatActivity) getActivity()).setSupportActionBar(mToolbar);
initRecyclerView();
populateRecyclerViewAdapter();
return view;
}
}
从外观上看,折叠工具栏会对设备的方向感到困惑,并向下设置工具栏的动画,而不是向上设置动画。