方向改变后过渡闪烁
Transition blink after orientation change
更新
我用 Google https://issuetracker.google.com/issues/63663775
打开了一个错误
我正在尝试在我当前的 Android 申请中雇用 makeSceneTransitionAnimation
。
我有一个来源 Activity
,其中包含一个 Fragment
,在片段中是一个 RecyclerView
。
当我单击 RecyclerView
中的图像时,我会转换到我的目标 Activity
,其中包含一个片段,该片段可以正确显示具有可接受动画的图像。
按后退按钮可以正确反转动画。
以上在纵向和横向方向上都能正常工作。
当我在查看目标 Fragment 时改变方向然后按返回按钮时,会出现闪烁问题。
还有其他问题,例如图像没有 return 直接到其原始位置,并且在较旧的设备上我看到水平线,就像来自调谐不好的模拟电视的干扰。
闪烁非常糟糕,设备屏幕完全变黑大约 500 毫秒。
我已经下载并部署了 google 示例共享元素转换应用程序,它似乎具有相同的 "Feature"。
我尝试了多种解决方案,其中 none 个有效,例如 。
Here's 一个出现问题的。
LOGCAT 添加
07-21 12:57:18.097 1962-1967/com.incentive.yellowpages I/zygote64: Do partial code cache collection, code=30KB, data=21KB
07-21 12:57:18.099 1962-1967/com.incentive.yellowpages I/zygote64: After code cache collection, code=30KB, data=23KB
07-21 12:57:18.099 1962-1967/com.incentive.yellowpages I/zygote64: Increasing code cache capacity to 128KB
07-21 12:57:20.540 1962-2058/com.incentive.yellowpages D/OkHttp: --> GET http://www.spyur.am/en/home/search-1/?company_name=Happy http/1.1
07-21 12:57:20.688 1962-1967/com.incentive.yellowpages I/zygote64: Do partial code cache collection, code=61KB, data=55KB
07-21 12:57:20.688 1962-1967/com.incentive.yellowpages I/zygote64: After code cache collection, code=61KB, data=55KB
07-21 12:57:20.688 1962-1967/com.incentive.yellowpages I/zygote64: Increasing code cache capacity to 256KB
07-21 12:57:21.084 1962-2058/com.incentive.yellowpages D/OkHttp: <-- 200 OK http://www.spyur.am/en/home/search-1/?company_name=Happy (543ms, unknown-length body)
07-21 12:57:22.197 1962-1967/com.incentive.yellowpages I/zygote64: Do full code cache collection, code=124KB, data=93KB
07-21 12:57:22.197 1962-1967/com.incentive.yellowpages I/zygote64: After code cache collection, code=98KB, data=59KB
07-21 12:57:22.377 1962-1967/com.incentive.yellowpages I/zygote64: Do partial code cache collection, code=101KB, data=79KB
07-21 12:57:22.378 1962-1967/com.incentive.yellowpages I/zygote64: After code cache collection, code=101KB, data=79KB
07-21 12:57:22.378 1962-1967/com.incentive.yellowpages I/zygote64: Increasing code cache capacity to 512KB
07-21 12:57:22.378 1962-1967/com.incentive.yellowpages I/zygote64: Compiler allocated 4MB to compile boolean org.jsoup.parser.HtmlTreeBuilderState.process(org.jsoup.parser.Token, org.jsoup.parser.HtmlTreeBuilder)
07-21 12:57:22.701 1962-1967/com.incentive.yellowpages I/zygote64: Compiler allocated 4MB to compile void android.view.View.<init>(android.content.Context, android.util.AttributeSet, int, int)
07-21 12:57:24.495 1962-1967/com.incentive.yellowpages I/zygote64: Do full code cache collection, code=245KB, data=178KB
07-21 12:57:24.495 1962-1967/com.incentive.yellowpages I/zygote64: After code cache collection, code=216KB, data=130KB
07-21 12:57:25.040 1962-2058/com.incentive.yellowpages D/OkHttp: --> GET http://www.spyur.am/en/companies/happy-print-printing-house/34896 http/1.1
07-21 12:57:25.101 1962-1962/com.incentive.yellowpages D/ViewRootImpl[DetailActivity]: changeCanvasOpacity: opaque=true
07-21 12:57:25.437 1962-2058/com.incentive.yellowpages D/OkHttp: <-- 200 OK http://www.spyur.am/en/companies/happy-print-printing-house/34896 (396ms, unknown-length body)
07-21 12:57:26.111 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 0
07-21 12:57:26.123 1962-1967/com.incentive.yellowpages I/zygote64: Do partial code cache collection, code=251KB, data=168KB
07-21 12:57:26.124 1962-1967/com.incentive.yellowpages I/zygote64: After code cache collection, code=249KB, data=168KB
07-21 12:57:26.124 1962-1967/com.incentive.yellowpages I/zygote64: Increasing code cache capacity to 1024KB
07-21 12:57:26.173 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 1
07-21 12:57:26.177 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 2
07-21 12:57:26.186 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 3
07-21 12:57:26.226 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 4
07-21 12:57:26.232 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 5
07-21 12:57:26.238 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 6
07-21 12:57:26.244 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 7
07-21 12:57:26.265 1962-1967/com.incentive.yellowpages I/zygote64: Compiler allocated 8MB to compile void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
07-21 12:57:26.437 1962-1962/com.incentive.yellowpages D/ViewRootImpl[DetailActivity]: changeCanvasOpacity: opaque=false
07-21 12:57:26.579 1962-1967/com.incentive.yellowpages I/zygote64: Compiler allocated 6MB to compile void android.view.ViewRootImpl.performTraversals()
07-21 12:57:27.754 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 0
07-21 12:57:27.761 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 1
07-21 12:57:27.765 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 2
07-21 12:57:27.772 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 3
07-21 12:57:27.784 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 4
07-21 12:57:27.788 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 5
07-21 12:57:27.792 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 6
07-21 12:57:27.796 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 7
07-21 12:57:29.889 1962-1962/com.incentive.yellowpages D/ViewRootImpl[DetailActivity]: changeCanvasOpacity: opaque=false
07-21 12:57:30.117 1962-1962/com.incentive.yellowpages D/ViewRootImpl[DetailActivity]: changeCanvasOpacity: opaque=false
07-21 12:57:30.756 1962-1962/com.incentive.yellowpages W/AutofillManager: Session 409360048 could not be restored
07-21 12:57:30.922 1962-1967/com.incentive.yellowpages I/zygote64: Do full code cache collection, code=498KB, data=362KB
07-21 12:57:30.923 1962-1967/com.incentive.yellowpages I/zygote64: After code cache collection, code=445KB, data=262KB
我认为问题出在 ImageView layoutbounds 上,因为场景转换会计算起始位置和结束位置之间的差异,然后为差异设置动画,但是由于方向改变,这里的结束位置发生了变化,你能尝试重新创建结束位置吗在方向改变的情况下,一旦你按下布局可能是我错了,但只能想到这种情况,你能提供相同的代码吗?(这太大了,无法添加为评论,所以必须添加为答案.)
问题在于:您开始 Activity2
时处于纵向模式,然后返回 Activity1
时处于横向模式。但是因为您执行了方向更改,Activity1
的视图层次结构被破坏并创建,因此不再有最初开始转换的 View
。
您可以做的是使用 Activity#setExitSharedElementCallback()
API. There's a bit of work to do to handle that situation though, which I've already described step-by-step in my 答案将旧视图重新映射到新视图。
您最好的选择是检查Alex Lockwood's app at github您需要的功能,这样您会更容易理解如何处理这种情况。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setExitSharedElementCallback(new SharedElementCallback() {
@Override
public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
if (we are coming back to Activity1) {
View newSharedElement = findViewById(R.id.your_imageview);
if (newSharedElement != null) {
names.clear();
names.add("transition name");
sharedElements.clear();
sharedElements.put("transition name", newSharedElement);
}
} else {
// we are leaving Activity1
}
}
});
}
基本上,您正在清除地图并添加新的 "transition name-view" 对
给它。您可以看到 if (we are coming back to Activity1)
检查是如何完成的 here.
这是在 one of my apps 中实现的功能。
这似乎只发生在奥利奥上。它可以使用 Google 的示例项目在 API 26 模拟器上重现:https://github.com/googlesamples/android-ActivitySceneTransitionBasic/#readme
我通过添加以下内容成功解决了我的应用程序中的问题:
<item name="android:windowIsTranslucent">true</item>
我详细的风格activity。
更新
我用 Google https://issuetracker.google.com/issues/63663775
打开了一个错误我正在尝试在我当前的 Android 申请中雇用 makeSceneTransitionAnimation
。
我有一个来源 Activity
,其中包含一个 Fragment
,在片段中是一个 RecyclerView
。
当我单击 RecyclerView
中的图像时,我会转换到我的目标 Activity
,其中包含一个片段,该片段可以正确显示具有可接受动画的图像。
按后退按钮可以正确反转动画。
以上在纵向和横向方向上都能正常工作。
当我在查看目标 Fragment 时改变方向然后按返回按钮时,会出现闪烁问题。
还有其他问题,例如图像没有 return 直接到其原始位置,并且在较旧的设备上我看到水平线,就像来自调谐不好的模拟电视的干扰。
闪烁非常糟糕,设备屏幕完全变黑大约 500 毫秒。
我已经下载并部署了 google 示例共享元素转换应用程序,它似乎具有相同的 "Feature"。
我尝试了多种解决方案,其中 none 个有效,例如
Here's 一个出现问题的。
LOGCAT 添加
07-21 12:57:18.097 1962-1967/com.incentive.yellowpages I/zygote64: Do partial code cache collection, code=30KB, data=21KB
07-21 12:57:18.099 1962-1967/com.incentive.yellowpages I/zygote64: After code cache collection, code=30KB, data=23KB
07-21 12:57:18.099 1962-1967/com.incentive.yellowpages I/zygote64: Increasing code cache capacity to 128KB
07-21 12:57:20.540 1962-2058/com.incentive.yellowpages D/OkHttp: --> GET http://www.spyur.am/en/home/search-1/?company_name=Happy http/1.1
07-21 12:57:20.688 1962-1967/com.incentive.yellowpages I/zygote64: Do partial code cache collection, code=61KB, data=55KB
07-21 12:57:20.688 1962-1967/com.incentive.yellowpages I/zygote64: After code cache collection, code=61KB, data=55KB
07-21 12:57:20.688 1962-1967/com.incentive.yellowpages I/zygote64: Increasing code cache capacity to 256KB
07-21 12:57:21.084 1962-2058/com.incentive.yellowpages D/OkHttp: <-- 200 OK http://www.spyur.am/en/home/search-1/?company_name=Happy (543ms, unknown-length body)
07-21 12:57:22.197 1962-1967/com.incentive.yellowpages I/zygote64: Do full code cache collection, code=124KB, data=93KB
07-21 12:57:22.197 1962-1967/com.incentive.yellowpages I/zygote64: After code cache collection, code=98KB, data=59KB
07-21 12:57:22.377 1962-1967/com.incentive.yellowpages I/zygote64: Do partial code cache collection, code=101KB, data=79KB
07-21 12:57:22.378 1962-1967/com.incentive.yellowpages I/zygote64: After code cache collection, code=101KB, data=79KB
07-21 12:57:22.378 1962-1967/com.incentive.yellowpages I/zygote64: Increasing code cache capacity to 512KB
07-21 12:57:22.378 1962-1967/com.incentive.yellowpages I/zygote64: Compiler allocated 4MB to compile boolean org.jsoup.parser.HtmlTreeBuilderState.process(org.jsoup.parser.Token, org.jsoup.parser.HtmlTreeBuilder)
07-21 12:57:22.701 1962-1967/com.incentive.yellowpages I/zygote64: Compiler allocated 4MB to compile void android.view.View.<init>(android.content.Context, android.util.AttributeSet, int, int)
07-21 12:57:24.495 1962-1967/com.incentive.yellowpages I/zygote64: Do full code cache collection, code=245KB, data=178KB
07-21 12:57:24.495 1962-1967/com.incentive.yellowpages I/zygote64: After code cache collection, code=216KB, data=130KB
07-21 12:57:25.040 1962-2058/com.incentive.yellowpages D/OkHttp: --> GET http://www.spyur.am/en/companies/happy-print-printing-house/34896 http/1.1
07-21 12:57:25.101 1962-1962/com.incentive.yellowpages D/ViewRootImpl[DetailActivity]: changeCanvasOpacity: opaque=true
07-21 12:57:25.437 1962-2058/com.incentive.yellowpages D/OkHttp: <-- 200 OK http://www.spyur.am/en/companies/happy-print-printing-house/34896 (396ms, unknown-length body)
07-21 12:57:26.111 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 0
07-21 12:57:26.123 1962-1967/com.incentive.yellowpages I/zygote64: Do partial code cache collection, code=251KB, data=168KB
07-21 12:57:26.124 1962-1967/com.incentive.yellowpages I/zygote64: After code cache collection, code=249KB, data=168KB
07-21 12:57:26.124 1962-1967/com.incentive.yellowpages I/zygote64: Increasing code cache capacity to 1024KB
07-21 12:57:26.173 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 1
07-21 12:57:26.177 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 2
07-21 12:57:26.186 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 3
07-21 12:57:26.226 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 4
07-21 12:57:26.232 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 5
07-21 12:57:26.238 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 6
07-21 12:57:26.244 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 7
07-21 12:57:26.265 1962-1967/com.incentive.yellowpages I/zygote64: Compiler allocated 8MB to compile void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
07-21 12:57:26.437 1962-1962/com.incentive.yellowpages D/ViewRootImpl[DetailActivity]: changeCanvasOpacity: opaque=false
07-21 12:57:26.579 1962-1967/com.incentive.yellowpages I/zygote64: Compiler allocated 6MB to compile void android.view.ViewRootImpl.performTraversals()
07-21 12:57:27.754 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 0
07-21 12:57:27.761 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 1
07-21 12:57:27.765 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 2
07-21 12:57:27.772 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 3
07-21 12:57:27.784 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 4
07-21 12:57:27.788 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 5
07-21 12:57:27.792 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 6
07-21 12:57:27.796 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 7
07-21 12:57:29.889 1962-1962/com.incentive.yellowpages D/ViewRootImpl[DetailActivity]: changeCanvasOpacity: opaque=false
07-21 12:57:30.117 1962-1962/com.incentive.yellowpages D/ViewRootImpl[DetailActivity]: changeCanvasOpacity: opaque=false
07-21 12:57:30.756 1962-1962/com.incentive.yellowpages W/AutofillManager: Session 409360048 could not be restored
07-21 12:57:30.922 1962-1967/com.incentive.yellowpages I/zygote64: Do full code cache collection, code=498KB, data=362KB
07-21 12:57:30.923 1962-1967/com.incentive.yellowpages I/zygote64: After code cache collection, code=445KB, data=262KB
我认为问题出在 ImageView layoutbounds 上,因为场景转换会计算起始位置和结束位置之间的差异,然后为差异设置动画,但是由于方向改变,这里的结束位置发生了变化,你能尝试重新创建结束位置吗在方向改变的情况下,一旦你按下布局可能是我错了,但只能想到这种情况,你能提供相同的代码吗?(这太大了,无法添加为评论,所以必须添加为答案.)
问题在于:您开始 Activity2
时处于纵向模式,然后返回 Activity1
时处于横向模式。但是因为您执行了方向更改,Activity1
的视图层次结构被破坏并创建,因此不再有最初开始转换的 View
。
您可以做的是使用 Activity#setExitSharedElementCallback()
API. There's a bit of work to do to handle that situation though, which I've already described step-by-step in my
您最好的选择是检查Alex Lockwood's app at github您需要的功能,这样您会更容易理解如何处理这种情况。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setExitSharedElementCallback(new SharedElementCallback() {
@Override
public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
if (we are coming back to Activity1) {
View newSharedElement = findViewById(R.id.your_imageview);
if (newSharedElement != null) {
names.clear();
names.add("transition name");
sharedElements.clear();
sharedElements.put("transition name", newSharedElement);
}
} else {
// we are leaving Activity1
}
}
});
}
基本上,您正在清除地图并添加新的 "transition name-view" 对
给它。您可以看到 if (we are coming back to Activity1)
检查是如何完成的 here.
这是在 one of my apps 中实现的功能。
这似乎只发生在奥利奥上。它可以使用 Google 的示例项目在 API 26 模拟器上重现:https://github.com/googlesamples/android-ActivitySceneTransitionBasic/#readme
我通过添加以下内容成功解决了我的应用程序中的问题:
<item name="android:windowIsTranslucent">true</item>
我详细的风格activity。