Android ActivityOptions.makeSceneTransitionAnimation 似乎不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24517620/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ActivityOptions.makeSceneTransitionAnimation doesn't seem to exist
提问by MohammadAG
Android L introduced a new animations feature: animating between similar Views in different activities. It's documented here.
Android L 引入了一个新的动画功能:在不同活动中的相似视图之间进行动画处理。它记录在这里。
I've tried to use ActivityOptions.makeSceneTransitionAnimation
, but it doesn't seem to be visible in the SDK (or in the jar at all), so I tried using reflection, and it returns a null value.
我尝试使用ActivityOptions.makeSceneTransitionAnimation
,但它似乎在 SDK(或根本不在 jar 中)中可见,所以我尝试使用反射,它返回一个空值。
Has anyone else got it working?
有其他人让它工作吗?
回答by MohammadAG
Okay, I got it working.
好的,我让它工作了。
It seems like setting the value in styles.xml is completely ignored for now.
现在似乎完全忽略了在 style.xml 中设置值。
You'll need to do this in each Activity's onCreate till that's fixed
您需要在每个活动的 onCreate 中执行此操作,直到修复为止
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
Transition transition = // load transition here.
getWindow().setSharedElementEnterTransition(transition);
getWindow().setSharedElementExitTransition(transition);
As per the same bug ViewAnimationUtils has, you'll see errors in Android Studio, it'll compile and run fine though.
根据 ViewAnimationUtils 的相同错误,您会在 Android Studio 中看到错误,但它会编译并运行良好。
回答by Vova K.
We can got it working with theme config for v21. Put these items into res/values-v21/styles.xml
我们可以让它与 v21 的主题配置一起工作。将这些项目放入 res/values-v21/styles.xml
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
回答by lannyf
Here is something work with 5.0 sdk got after 10/17/14.
这是 14 年 10 月 17 日之后使用 5.0 sdk 的一些工作。
But not sure what is the expected behavior if enable window content transitions and called setEnterTransition
/setExitTransition
in both mainActivity
and secondActivity
. If they are different (e.g one choose Explode and other choose Slide), which one would be applied?
但不知道什么是预期的行为,如果让窗口内容的转变,并呼吁setEnterTransition
/setExitTransition
两mainActivity
和secondActivity
。如果它们不同(例如,一个选择爆炸,另一个选择幻灯片),将应用哪一个?
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*
To enable window content transitions in your code instead, call the Window.requestFeature() method:
*/
getWindow().requestFeature(android.view.Window.FEATURE_CONTENT_TRANSITIONS);
Transition ts = new Explode(); //Slide(); //Explode();
ts.setStartDelay(2000);
ts.setDuration(5000);
/*
If you have set an enter transition for the second activity,
the transition is also activated when the activity starts.
*/
getWindow().setEnterTransition(ts);
getWindow().setExitTransition(ts);
setContentView(R.layout.activity_main_view);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, mainViewFragment.newInstance())
.commit();
}
}
public void launchSecondActivity() {
/*
If you enable transitions and set an exit transition for an activity,
the transition is activated when you launch another activity as follows:
*/
Intent listIntent = new Intent(this, secondActivity.class);
startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
}
}
//===
//===
public class secondActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
///
getWindow().requestFeature(android.view.Window.FEATURE_CONTENT_TRANSITIONS);
Transition ts = new Slide(); //Slide(); //Explode();
ts.setDuration(3000);
getWindow().setEnterTransition(ts);
getWindow().setExitTransition(ts);
///
setContentView(R.layout.activity_scene_transition);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}