1

I have an app that has a minSdk of 15 and I'm working out all the bugs that came with the lollipop upgrade. Our software is very complex and it dynamically creates views using custom ViewGroups and then an array of elements that are explicitly sized and placed inside the group. I'm running into an issue where for example I'll have a ViewGroup and the first child object is a Button...this button is sized to fill the view (not clickable). The second child is a FrameLayout containing a single view. This single view is a video object. In all prior versions of Android this works just fine. The FrameLayout is layered over the button (that is acting as a background) and the video is inside the framelayout. You can interact with the video without any issues.

Something changed in lollipop - suddenly, even though the button is showing up as the 0 index element, it is laying OVER the rest of the children...so I cannot get to the video underneath. If I remove that button element, the video renders and plays just fine...I have no issues interacting with it.

I ran the app in UI Automator Viewer just to make sure I was really setting up the UI as I expected (keep in mind the entire view is dynamically rendered at runtime using image/video assets and xml config files).

I'm not able to share code since this is proprietary software, but I am working on a little test project to see if I can manually recreate the issue with static objects. Once I get that up and running I'll be sure to update this ticket. For now, here is a screenshot of the hierarchy:

https://goo.gl/photos/a8on9CJDnN66XYnV6

Notice the highlighted object, this is the custom ViewGroup, the children below it are what I am describing above.

Does anyone know of a change in Lollipop that would effect the ordering of things? I found earlier that if you have a disabled object but don't have a disabled state drawable assigned to that object it would become invisible, previous versions just used one of the other state drawables..okay that makes sense and it was very easy to fix, but this object is not invisible...so it must be something different.

Any direction would be greatly appreciated. ~A

UPDATE -- FIXED

With the help of @alanv and @BladeCoder I figured out this functionality was due to the new elevation feature of Material design. I was able to fix my particular issue by first checking what version of android the device was using, and if lollipop, I just add this new property to the button:

android:stateListAnimator="@null"

This prevents my explicit child hierarchy from being overridden by the OS.

4

2 回答 2

1

好的,更新!我想出了如何解决这个问题,尽管我仍然不确定(即使在倾注了 grepcode 中几个类之间的差异之后)棒棒糖中的哪些变化导致了它的工作方式发生了变化。

如果按钮已启用...并且您使用与 AbsoluteLayout 等效的东西来放置它(我们有自己创建的称为 Explicit 布局的 ViewGroup,但它的作用与 AbsoluteLayout 几乎相同),它将始终位于任何东西之上堆栈中的其他按钮也不是某种按钮(至少这是我发现的......我没有测试所有可能的小部件)。

将纯粹用作背景图像的按钮设置为 enabled=false 可以解决此问题。我知道,我们使用按钮作为背景图像是没有意义的,但是我们的代码使用它来创建动态元素,因此每个元素都有许多可能的状态和用途。

无论如何,不​​确定其他人是否会遇到这个问题,但以防万一你这样做......在这里。

谢谢!

于 2015-06-03T22:16:53.930 回答
1

Lollipop 引入了高程作为将元素定位在 Z 轴上的一种方式,并根据它们的高程差异在它们之间投射阴影。

启用按钮的默认高度为 2dp(按下它们时会增加)。因此,您的按钮具有比FrameLayout(默认为 0dp)更高的高度,因此它将被绘制在其顶部。

禁用按钮的高度为 0dp。这就是为什么禁用该按钮可以解决您的问题。

使用按钮作为背景看起来是个坏主意(为什么不设置自定义Drawable背景FrameLayout呢?)但如果你真的需要,你可以像以前一样禁用按钮,并且为了确保将其高度强制为 0dp。另一种解决方法是增加 FrameLayout 的高度,但如果它有背景,它可能会在 Lollipop 下投下很大的阴影,也许这不是你想要的。

于 2015-06-04T09:33:55.130 回答