scenes 保存了一个包含视图里面的所有Views及属性的状态
2.1 使用布局文件创建:
// Create the scenes
mAScene =Scene.getSceneForLayout(mSceneRoot, R.layout.a_scene,this);
2.2 使用ViewGrop创建:
mScene =new Scene(mSceneRoot, mViewHierarchy);
3.1 在接下来的例子中包含以下3个布局定义:
1)主布局包含一个TextView和子布局:
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/master_layout">
<TextView
android:id="@+id/title"
...
android:text="Title"/>
<FrameLayout
android:id="@+id/scene_root">
<includelayout="@layout/a_scene"/>
</FrameLayout>
</LinearLayout>
2)开始Scene的是包含2个TextView的相对布局:res/layout/a_scene.xml
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scene_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text_view1
android:text="TextLine 1" />
<TextView
android:id="@+id/text_view2
android:text="TextLine 2" />
</RelativeLayout>
3)结束Scene的也是包含2个TextView的相对布局,只是2个TextView的顺序不一样:
res/layout/another_scene.xml
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"3.2 通过布局文件生成Scenes
android:id="@+id/scene_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text_view2
android:text="TextLine 2" />
<TextView
android:id="@+id/text_view1
android:text="TextLine 1" />
</RelativeLayout>
Scene mAScene;
Scene mAnotherScene;
// Create the scene root for the scenes in this app
mSceneRoot =(ViewGroup) findViewById(R.id.scene_root);
// Create the scenes
mAScene =Scene.getSceneForLayout(mSceneRoot, R.layout.a_scene,this);
mAnotherScene =
Scene.getSceneForLayout(mSceneRoot, R.layout.another_scene,this);
//get the layout IDRelativeLayout baseLayout = (RelativeLayout)findViewById(R.id.base);
//first sceneViewGroup startViews = (ViewGroup)getLayoutInflater().inflate(R.layout.start_layout, baseLayout, false);
//second sceneViewGroup endViews = (ViewGroup)getLayoutInflater().inflate(R.layout.end_layout, baseLayout, false);//create the two scenesscene1 = new Scene(baseLayout, startViews);scene2 = new Scene(baseLayout, endViews);
场景动作用于处理以下情况:
1)不同层级的动画视图(Animate views that are not in the same hierarchy)
2)像ListView这种Transition框架不适用的动画视图。
参考:http://developer.android.com/intl/zh-cn/training/transitions/transitions.html