【发布时间】:2015-06-13 06:53:25
【问题描述】:
我有 MainActivity,它使用下面的 xml 实现 Navigation Drawer:
<android.support.v4.widget.DrawerLayout
xmlns:android ="http://schemas.android.com/apk/res/android"
android:id ="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
</LinearLayout>
<FrameLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#FFFFFF"/>
</LinearLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity ="start"
>
<ListView
android:id="@+id/drawerList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:divider="@color/material_blue_grey_800"
android:dividerHeight="1dp"
android:background="#FFFFFF"
/>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
现在我的列表视图中有 3 个项目,单击其中任何一个项目时,我的代码将 Framelayout 替换为该特定片段,如下所示:
Fragment f1 = new Fragment()
FragmentTransaction ft = getSupportFragmentManager().beginTransaction()
ft.setCustomAnimations(R.anim.slide_in,R.anim.hyper_out,R.anim.hyper_in,R.anim.slide_out)
ft.replace(R.id.content, f1).addToBackStack(null).commit();
上面的代码可以很好地根据需要用自定义动画替换片段。但是,我的问题是如何在片段事务期间为工具栏与片段一起设置动画。
所有片段都有各自的工具栏标题,这些标题在每个片段类的 onActivityCreated() 方法中通过以下代码进行更改:
((AppCompatActivity)getActivity()).getSupportActionBar().setTitle("Title");
我应该在我的布局中应用动画来掩盖工具栏吗?
【问题讨论】:
标签: android animation android-fragments