gpt4 book ai didi

使用 Android L 最新支持 v4 的 Android Activity 转换

转载 作者:IT老高 更新时间:2023-10-28 23:29:36 26 4
gpt4 key购买 nike

我正在为我的应用实现 Material 设计。我看到可以在这里进行 Activity 之间的转换:http://android-developers.blogspot.com.es/2014/10/implementing-material-design-in-your.html

所以我试着按照“真实 Action ”部分所说的:

ActivityMain.java

Intent intent = new Intent();
String transitionName = getString(R.string.transition_album_cover);

ActivityOptionsCompat options =
ActivityOptionsCompat.makeSceneTransitionAnimation(activity,
albumCoverImageView, // The view which starts the transition
transitionName // The transitionName of the view we’re transitioning to
);
ActivityCompat.startActivity(activity, intent, options.toBundle());

activity_main.xml

<ImageView

android:transitionName="@string/transition_album_cover" />

activity_details.xml

<ImageView

android:transitionName="@string/transition_album_cover" />

但是,这似乎使默认的 android Activity 转换,我看不到任何动画。

请记住,我调用了 requestWindowFeature(Window.FEATURE_CONTENT_TRANSITIONS),正如这里所说的 http://developer.android.com/reference/android/support/v4/app/ActivityOptionsCompat.html#makeSceneTransitionAnimation(android.app.Activity , android.view.View, java.lang.String)

所有这些都使用 Nexus4 API Level 19 进行了测试

问题出在哪里?

最佳答案

ActivityOptionsCompat.makeSceneTransitionAnimation 仅适用于 API 级别 >= 21。来自 docs :

Some material design features like the material theme and custom activity transitions are only available on Android 5.0 (API level 21) and above. However, you can design your apps to make use of these features when running on devices that support material design and still be compatible with devices running previous releases of Android.

这是它的定义:

public static ActivityOptionsCompat makeSceneTransitionAnimation(Activity activity,
View sharedElement, String sharedElementName) {
if (Build.VERSION.SDK_INT >= 21) {
return new ActivityOptionsCompat.ActivityOptionsImpl21(
ActivityOptionsCompat21.makeSceneTransitionAnimation(activity,
sharedElement, sharedElementName));
}
return new ActivityOptionsCompat();
}

So why does that method exist in support package?

这样做是为了保持与旧版本的向后兼容性(api 级别 <=20)。来自 maintaining compatibility docs :

// Check if we're running on Android 5.0 or higher
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Call some material design APIs here
} else {
// Implement this feature without material design
}

关于使用 Android L 最新支持 v4 的 Android Activity 转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26688374/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com