我使用Android的新过渡管理器附带4.4 Kit-Kat。
我有imageView
的两个场景,如下所示:
expanded_scene.xml
<ImageView
android:id="@+id/avatar"
android:layout_width="125dp"
android:layout_height="125dp"
android:contentDescription="@string/avatar"
android:scaleType="fitXY"
android:src="@drawable/avatar"
android:layout_centerInParent="true" />
collapsed_scene.xml
<ImageView
android:id="@+id/avatar"
android:layout_width="50dp"
android:layout_height="50dp"
android:contentDescription="@string/avatar"
android:scaleType="fitXY"
android:src="@drawable/avatar"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" />
change_bounds.xml
<?xml version="1.0" encoding="utf-8"?>
<changeBounds/>
transition_mgr.xml
<transitionManager
xmlns:android="http://schemas.android.com/apk/res/android">
<transition
android:toScene="@layout/collapsed_scene"
android:transition="@anim/change_bounds"/>
<transition
android:toScene="@layout/expanded_scene"
android:transition="@anim/change_bounds"/>
</transitionManager>
代码
public class MainActivity extends Activity {
private ViewGroup mSceneRoot;
private Scene mSceneExpanded;
private Scene mSceneCollapsed;
private TransitionManager mTransitionManager;
private boolean collapse;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSceneRoot = (ViewGroup) findViewById(R.id.sceneRoot);
TransitionInflater inflater = TransitionInflater.from(this);
mSceneExpanded = Scene.getSceneForLayout(mSceneRoot, R.layout.expanded_scene, this);
mSceneCollapsed = Scene.getSceneForLayout(mSceneRoot, R.layout.collapsed_scene, this);
mTransitionManager = inflater.inflateTransitionManager(R.anim.transitions_mgr,
mSceneRoot);
Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mTransitionManager.transitionTo(collapse ?mSceneCollapsed:mSceneExpanded);
collapse = !collapse;
}
});
}
}
当我使用从展开到折叠场景的转换时,图像会在没有动画的情况下调整大小,然后动画到其坐标。 如果我向后改变场景,图像将转到新坐标,然后使用动画调整大小。
我只在<changeBounds/>
transitionSet
我如何同时为边界设置动画?