在具有非静态片段的布局上有效地使用布局编辑器 [英] Use layout editor effectively on layouts with non-static fragments
问题描述
所有的Android开发工具都非常出色,尤其是在版本21之前,图形布局编辑器是一个功能强大的工具,可以对每个配置和区域设置的片段进行视图控制。我知道典型的活动
的布局XML将包含静态片段
标签,其中嵌入了布局编辑器的信息,例如 tools:layout =@ layout / book_collection_view_window_list
。
With all the Android development tools greatness, especially as of version 21, the graphical layout editor is a powerful tool to have visual control over a layout with fragments for every configuration and locale. I'm aware that a typical Activity
's layout XML will contain static fragment
tags with info embedded for the layout editor, for example tools:layout="@layout/book_collection_view_window_list"
.
然而,因为我需要替换片段
在我的窗口动态,我不能使用静态片段
标签,而是需要提供容器,如 FrameLayout
,我可以在 replace()
中引用它。有什么像工具:布局
或工具:上下文
我可以在这个容器上使用,所以在布局编辑器中有不仅仅是黑色空洞,所以我可以利用它会给我的设计和验证功能。
However, because I need to replace the Fragments
in my window dynamically, I cannot use the static fragment
tags, and instead need to provide containers, such as FrameLayout
, to which I can refer in replace()
. Is there something like tools:layout
or tools:context
I can use on this container so in the layout editor there is more than just black emptyness, and so I can leverage the design and verification features it would give me?
推荐答案
至 FrameLayout的文档
,就像您可以在 FrameLayout
标签上使用的属性在ViewGroup的前台放置一个可绘制的。
It looks, according to the documentation for FrameLayout
, like there is an attribute you can use on the FrameLayout
tag to put a drawable in the foreground of the ViewGroup.
您可以在设置视图时使用它来查看FrameLayout。我经常只是放一个颜色,所以我可以看到它是相对于背景和其他查看
s。
You could use this to see the FrameLayout whilst you are setting up your view. I often just put a colour in so I can see where it is relative to the background and other View
s.
这篇关于在具有非静态片段的布局上有效地使用布局编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!