如何将视图发送回?如何以编程方式控制 z 顺序? [英] How to send view to back ? How to control the z-order programmatically?

查看:17
本文介绍了如何将视图发送回?如何以编程方式控制 z 顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法将视图发送回去.在 Android 中,我们有一个类似于 bringToFront() 的方法,可以将视图放置在另一个视图的顶部.像那样,我想把视图放在上一张图片的下面.

I have a problem to send the view to back. In Android we have a method like bringToFront(), to place the view on top of the another view. Like that, I want to put the view on below the previous image.

Android 中有没有像 sendToBack()bringToBack() 这样的方法.如果是这样,任何人都可以帮助我.

Is there any method like sendToBack() or bringToBack() in Android. If so, can any one help me in this.

注意:我不想通过在布局中放置项目的顺序来控制 z-order 我想以编程方式控制 z-order.

Note: that I do not want to control the z-order by the order of placing items in layout I want to control the z-order programmatically.

我不想隐藏前面的视图,我只是希望它们位于移动的视图后面.

I do not want to hide the views on the front I just want them to be behind the view that is moving.

推荐答案

Afaik 对此没有内置解决方案.我猜您正在尝试修改 FrameLayout 或类似内容中的 z 顺序.

Afaik there's no built-in solution for this. I guess you're trying to modify the z-order in a FrameLayout, or something similar.

但是,我认为您可以修改布局中包含的子元素的顺序.RemoveChild...() 和 addView() 方法可以采用位置值,因此您很可能可以交换子元素,这将修改 z 顺序.然而,这似乎是一个有点hacky的解决方案.

However, I think you can modify the order of the contained child elements in the layout. RemoveChild...() and addView() methods can take position values, so you could most likely swap child elements around, and that would modify the z-order. It seems a bit hacky solution however.

或者考虑修改子视图的可见性属性,你可能会得到类似的行为,我认为这会更清晰.

Or consider modifying the visibility property of the child views, you may get similar behaviour, and that'd be much cleaner I think.

借助新的 Android 版本 L Developer Preview,我们似乎终于能够轻松更改视图的 Z 顺序.'Elevation' 和 'TranslationZ' 属性来救援:https://developer.android.com/preview/material/views-shadows.html

With the new Android version, the L Developer Preview it seems that at last we have the ability to easily change the Z ordering of Views. 'Elevation' and 'TranslationZ' properties to the rescue: https://developer.android.com/preview/material/views-shadows.html

这篇关于如何将视图发送回?如何以编程方式控制 z 顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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