如何使用正确的视图 z 顺序在 android 中实现此基本布局

发布于 2024-09-18 16:34:19 字数 446 浏览 5 评论 0原文

Android 中如何实现如下布局?

我想要的是让 3 个蓝色框在它们的视图中顶部对齐,然后我想让红色框在蓝色框下方居中,但是这样当我将红色框动画化时,它会滑到蓝色框下方蓝色盒子。

我尝试将蓝色和红色框放置在不同的布局中,但是一旦我将红色框动画化,如果它超出其布局的边界,它就会消失(我不希望红色框的布局剪裁红色框)框,我希望红色框滑动到蓝色框下方,以便蓝色框遮挡红色框。)

我还设法使用一系列嵌套布局创建此布局,但由于绘制顺序,红色框始终出现在蓝色框的顶部。我尝试使用 BringToFront() 方法,但我发现这只适用于同一布局中的同级视图。不幸的是,我无法在将所有 4 个视图保留在同一布局中的同时获得这种类型的布局。有什么建议吗? (另外,如果有人对这个问题的标题有更好的建议,我会洗耳恭听)

alt text

How can I achieve the following layout in Android?

What I would like, is to have the 3 blue boxes top aligned in their view, and then I'd like to have the red box centered underneath the blue boxes, but so that when I animate the red box up, it slides underneath the blue box.

I have tried placing the blue and red boxes in different layouts, but as soon as I animate the red box up, if it goes outside the border of its layout, it disappears (I don't want the red box's layout to clip the red box, I want the red box to slide under the blue box so that the blue box occludes the red box.)

I have also managed to create this layout using a series of nested layouts, but because of the draw order, the red box always appears on top of the blue box. I attempted to use the bringToFront() method, but I found out that this only works on sibling views within the same layout. Unfortunately I can't get this type of layout while keeping all 4 views within the same layout. Any suggestions? (also, if anyone has better suggestions for the title of this question I'm all ears)

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烂柯人 2024-09-25 16:34:19

尝试使用RelativeLayout。如果您知道蓝色框的高度,则可以始终先绘制红色框,然后在布局中添加蓝色框,这将确保蓝色框始终位于红色框的顶部。

您还可以考虑使用 SurfaceView,您可以在其中轻松订购商品,而无需任何 xml 定义...

try to use the RelativeLayout. If you know the height of the blue box, you can draw the red box always first and add the blue box later in your layout which will make sure, that the blue box is always on top of the red one.

You could also consider using a SurfaceView where you can order you items easily and without any xml definition...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文