允许单个子视图溢出视图组边界的方法?
以下屏幕截图说明了我现在所拥有的一个简单示例:
我想要实现的是所选(蓝色)视图不会在红色容器的边界处被剪裁。我的第一次尝试是clipChildren =“false”,这会导致蓝色视图扩展到其边界之外,填充红色区域。我只想看看覆盖绿色区域的部分。
The following screenshot illustrates a simple example of what I have now:
What I'd like to achieve, is that the selected (blue) view not be clipped at the boundary of the red container. My first try was clipChildren="false", which causes the blue view to expand outside of its borders, filling the the red area. I just want to see the portion overlaying the green area.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你必须将蓝色漂浮在红色和绿色之上。您不能在其父 ViewGroup 之外拥有子视图(AFAIK)。您需要重新设计布局。
不过,得到你想要的东西应该很容易。我不使用图形设计器,因此需要 XML。
FrameLayout 内部带有 LinearLayout 以显示红色/绿色,然后在第一个 LinearyLayout (在 FrameLayout 内部)之后显示另一个 Linear 或relative。使用 LinearLayout,我会向右对齐,并给蓝色元素一些填充。
也许可以使用RelativeLayout 来完成这一切,但我倾向于远离它。
I think you'll have to float the blue on top of both the red and green. You can't have a child outside of its parent ViewGroup (AFAIK). You'll need to redesign your layout.
Getting what you want should be pretty easy, though. I don't use the graphical designer, so would need XML.
FrameLayout with LinearLayout inside to show the Red/Green, then another Linear or Relative after the first LinearyLayout (inside the FrameLayout). With LinearLayout, I'd align right, and give the blue element some padding.
It may be possible to do this all with RelativeLayout, but I tend to stay away from it.
本质上,您正在寻找的是重叠的视图。这可以通过 FrameLayout 来完成。有关如何执行此操作的信息,请查看 这个例子。
Essentially what you're looking for is overlapping views. This can be done with a FrameLayout. For information on how to do this, please checkout this example.