方向改变后转换闪烁

时间:2017-07-04 14:31:32

标签: android animation android-animation android-transitions shared-element-transition

更新

我用Google https://issuetracker.google.com/issues/63663775

打开了一个错误

我正在尝试在我当前的Android应用程序中使用makeSceneTransitionAnimation

我有一个来源Activity,其中包含Fragment,而且片段中有一个RecyclerView

当我点击RecyclerView中的图片时,我转换到我的目标Activity,其中包含一个正确显示带有可接受动画的图像的片段。

按后退按钮可正确反转动画。

以上在纵向和横向都可以正常工作。

当我在查看目标片段时更改方向然后按后退按钮时,会出现BLINKING问题。

还有其他问题,例如图像没有直接返回到原始位置,而在较旧的设备上,我看到水平线条,如来自严重调谐的模拟电视的干扰。

它的BLINKING非常糟糕,设备屏幕完全黑色约500ms。

我已下载并部署了Google示例共享元素转换应用,它似乎具有相同的"功能"。

我尝试了多种解决方案,但没有一种方法有效,例如this

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$7.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

3 个答案:

答案 0 :(得分:4)

问题在于:您是以纵向模式启动Activity2并以横向模式返回Activity1。但是因为您已经执行了方向更改,所以Activity1的视图层次结构被销毁并创建,因此不再有最初转换开始的View

您可以做的是使用Activity#setExitSharedElementCallback() API将视图从旧视图重新映射到新视图。虽然我已经做了一些工作来处理这种情况,我已经在我的this答案中逐步描述了这一点。

最好的选择是结帐Alex Lockwood 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
            }
        }
    });
}

基本上,您正在清除地图并添加新的&#34;转换名称视图&#34;对 它。您可以查看if (we are coming back to Activity1)检查是如何完成的here

此功能在one of my apps中实现。

enter image description here

答案 1 :(得分:2)

我认为问题在于ImageView布局边界,因为场景转换计算起始位置和结束位置之间的差异,然后设置差异动画,但是这里由于方向改变而改变了结束位置,您可以尝试重新创建结束布局如果在方向改变的情况下你背压可能我错了但是只能想到这个场景,你能提供相同的代码吗?(这太大了,不能添加为评论所以必须添加作为答案。)

答案 2 :(得分:1)

这似乎只发生在奥利奥身上。它可以使用Google的示例项目在API 26模拟器上重现:https://github.com/googlesamples/android-ActivitySceneTransitionBasic/#readme

我设法通过添加以下内容来修复我的应用中的问题:

<item name="android:windowIsTranslucent">true</item>

符合我的细节活动风格。