相关疑难解决方法(0)

在Intellij IDEA/Android Studio中使用合并根标签预览布局

让我们假设我们正在开发基于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);
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我们将使用它LinearLayout作为根somelayout.xml,我们将有额外的视图级别,所以我们使用merge标记:

<?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>
Run Code Online (Sandbox Code Playgroud)

但是在IDE中的预览选项卡中,合并始终充当FrameLayout,我们会看到类似的东西: 合并预览

(这是Android Studio,Intellij IDEA也一样,关于Eclipse我不知道)

预览加快了布局的开发速度,即使对于某些布局,它也会失去如此大的帮助.可能有一种方法可以指定,预览应该如何解释merge特定布局中的标签?

android intellij-idea android-layout android-studio android-tools-namespace

146
推荐指数
2
解决办法
2万
查看次数