preVIEW布局中的IntelliJ IDEA / Android的工作室合并根标签 [英] Preview layout with merge root tag in Intellij IDEA/Android Studio

查看:173
本文介绍了preVIEW布局中的IntelliJ IDEA / Android的工作室合并根标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们想象一下,我们正在开发基于复合的LinearLayout组件。所以,我们创建类是这样的:

Let's imagine we are developing compound component based on LinearLayout. So, we create class like this:

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 的根,我们将有额外的视图级,所以我们使用合并标记:

If we'll use LinearLayout as a root of somelayout.xml, we'll have extra view level, so we use merge tag:

<?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_height="wrap_content" android:layout_width="wrap_content"
              android:text="Some text"
              android:textSize="20sp"
            />
    <TextView android:layout_height="wrap_content" android:layout_width="wrap_content"
              android:text="Some other text"
            />
</merge>

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

But in Preview tab in IDE merge always acts as FrameLayout, and we'll see something like that:

(这是Android的工作室,IntelliJ IDEA的是一样的,关于Eclipse我不知道)

(It is Android Studio, Intellij IDEA is just the same, about Eclipse I don't know)

preVIEW加快发展布局了很多,这是可悲的丧失,甚至对一些布局等有很大的帮助。可能是有指定的方式,如何preVIEW应该相互preT 在特定布局合并标记?

Preview speed up developing layouts a lot, it's sad lose such a great help even for some layouts. May be there is a way to specify, how Preview should interpret merge tag in particular layout?

推荐答案

Android的工作室0.5.8增加了对工具:舒。通过使用它是可能的preVIEW&下;合并>的布局。

Android Studio 0.5.8 added support for tools:showIn. By using it it is possible to preview < merge > layouts.

<一个href=\"http://tools.android.com/recent/androidstudio058released\">http://tools.android.com/recent/androidstudio058released

与工具的布局/ layout_merge.xml:舒:

layout/layout_merge.xml with tools:showIn:

<merge xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:custom="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   tools:showIn="@layout/simple_relativelayout">

......

</merge>

与布局/ simple_relativelayout.xml包括:

layout/simple_relativelayout.xml with include:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include layout="@layout/layout_merge"/>

</RelativeLayout>

这篇关于preVIEW布局中的IntelliJ IDEA / Android的工作室合并根标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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