替换片段的高程值错误 [英] Replacing fragments have wrong elevation value

本文介绍了替换片段的高程值错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,再次堆叠溢出对象.我还有另一个片段问题.(我使用的是android.app.Fragment不支持片段)

Hello again stack overflowians. I have another fragment question. (I'm using android.app.Fragment not Support Fragments)

我正在尝试替换一个片段.但这并不像使用这样简单:

I'm trying to replace a fragment. But this isn't as simple as using:

fragmentTransaction
    .replace(containerId, newFragment)
    .addToBackStack("unique tag")
    .commit()

为什么不呢?朋友问得好,这是因为我的 newFragment 具有过渡动画.

Why not? Good question friends, its because my newFragment has a transition animation.

动画在哪里定义?另一个好问题,它在onCreateAnimator()片段中定义

Where is the animation defined? Another great question, its defined in the fragments onCreateAnimator()

为什么在其中定义它?一个很长的答案,可以找到原因:

Why is it defined there? A long answer to why can be found: Nested fragments transitioning incorrectly. For now you need to trust that this is how things need to be done in my project.

动画在做什么?从屏幕边缘到屏幕中心的简单滚动,完全覆盖了原始片段.请记住,在这种情况下,旧片段只是就位.它具有动不动的动画效果.

What is the animation doing? A simple scroll from the edge of the screen into the center of it, completely covering the original fragment. Keep in mind that in this scenario the old fragment is just sitting in place. It has an animation effect to not move.

问题在于newFragment的标高(或z?)值似乎比旧的标高低.因此,由于旧片段位于新片段上方,因此无法观察到过渡.到达动画持续时间结束时,您会看到新片段在旧片段上方闪烁.我希望newFragment从动画开始就覆盖旧的片段.

The problem is that newFragment seems to have a lower elevation (or z?) value than the old one. So the transition isn't able to be observed because the old fragment is sitting above the new fragment. Upon reaching the end of the animation duration you see the new fragment blink above the old one. I expected the newFragment to cover the old one from the beginning of the animation.

为什么不使用add?,这似乎会带来更多问题,因为我想交换视图中的很多片段.即使我前面有1 ... n个片段,使用add似乎会在下次我使用replace时触发其退出动画.他们也不会暂停.

Why not use add? This seems to create more problems, as I have many fragments I want to swap in and out of the view. Using add seems to trigger their exit animations the next time I use replace, even if there are 1...n fragments in front of it. They also don't pause.

为什么不设置海拔高度?,因为我支持的API 19没有海拔高度属性.

Why not set the elevation? Because I'm supporting api 19 which doesn't have an elevation property.

为什么不对api 19使用ViewCompat.setElevation()?我尝试了一下,但结果仍然相同.

Why not use ViewCompat.setElevation() for api 19? I tried it and have the same failing results.

有人找到解决这个问题的方法吗?

Has anyone found a way to get around this problem?

推荐答案

我遇到了同样的问题,并且花了很多时间来修复它.不幸的是,根据我的经验,在这种设置下无法使其适用于API< = 19.

I had the same problem, and spent quite a lot of time trying to fix it. Unfortunately, from my experience, there's no way to make it work for API <=19 on this setup.

ViewCompat.setElevation()只是< = 19 API的NoOp,因此它不起作用.从SDK 21开始,它可以设置海拔高度,并且可以解决此问题.设置Z索引也可以.

ViewCompat.setElevation() is simply a NoOp for <=19 API, so it can't work. Starting from SDK 21, it sets an elevation and it kinda fixes the problem. Setting Z index works as well.

我唯一可以建议的就是更改API <= 19的过渡,以使其不依赖于Z索引.对于21岁以上的人,请使用您想要的过渡.我就是这样做的,我认为这很好,因为大多数用户的年龄都在21岁以上.

The only thing I can advice is to change the transition for API <=19 to not depend on the Z index anyhow. And for 21+ use the transition you wanted. This was the way I did it, and I think it's fine, because the majority of users are on 21+.

这篇关于替换片段的高程值错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆