【发布时间】:2013-06-22 04:53:43
【问题描述】:
假设我们正在开发基于 LinearLayout 的复合组件。所以,我们创建这样的类:
public class SomeView extends LinearLayout {
public SomeView(Context context, AttributeSet attrs) {
super(context, attrs);
setOrientation(LinearLayout.VERTICAL);
View.inflate(context, R.layout.somelayout, this);
}
}
如果我们使用LinearLayout 作为somelayout.xml 的根,我们会有额外的视图级别,所以我们使用合并标签:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some text"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some other text"/>
</merge>
但在 IDE 中的 Preview 选项卡中,合并始终充当 FrameLayout,我们会看到类似的内容:
(就是Android Studio,Intellij IDEA也一样,关于Eclipse我就不知道了)
预览版大大加快了布局的开发速度,即使对于某些布局也失去了这么大的帮助,这很遗憾。可能有办法指定,预览应该如何解释特定布局中的merge标签?
【问题讨论】:
-
我希望也能添加此支持。
-
这可能会在未来某个时间通过工具属性解决。 code.google.com/p/android/issues/detail?id=61652
标签: android android-layout android-studio intellij-idea android-tools-namespace