警告:此< FrameLayout>可以用< merge>替换标签 [英] Warning: This <FrameLayout> can be replaced with a <merge> tag

查看:252
本文介绍了警告:此< FrameLayout>可以用< merge>替换标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 FrameLayout ,其中包含一个 TextView 和两个 LinearLayout s:

I have a FrameLayout that contains a TextView and two LinearLayouts:

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


    ... a textview and 2 linearlayouts


</FrameLayout>

运行Android Lint之后,我得到以下警告: This< FrameLayout>可以用< merge>替换标签。

After running Android Lint, I get this warning: This <FrameLayout> can be replaced with a <merge> tag.

为什么存在此警告?我可以做些什么来解决它(除了忽略)?

Why does this warning exist? What can I do to fix it (other than ignore)?

推荐答案

要了解这一点,您需要了解布局是如何膨胀和放置的。

To understand this, you need to understand how layouts are inflated and placed.

例如,您有一个活动,这是您使用的布局xml。这是放置布局文件之前活动布局的外观。

Let's say for example, you have an activity and this is the layout xml you use. Here is what the layout of the activity looks before you put your layout file.

<FrameLayout> // This is the window
    <FrameLayout> // This is activity
    </FrameLayout>
</FrameLayout>

根据设备/操作系统的不同,其他层可能很少。

There might be few other layers depending on the device/OS.

现在,当您膨胀布局文件并将其放进去时,它就是这样。

Now when you inflate your layout file and put it in, this is how it will look.

<FrameLayout> // This is the window
    <FrameLayout> // This is activity
            //A textview and 2 linearlayouts
    </FrameLayout>
</FrameLayout>

您是否在其他 FrameLayout内部看到了 FrameLayout 强>?这样做是多余的,因为它不会增加太多价值。要进行优化,可以将外部框架布局替换为< merge> 标签。

Do you see the FrameLayout inside the other FrameLayout? It is redundant to have that since it does not add much value. To optimize, you can replace your outer FrameLayout with the <merge> tag. This is what it will look like.

<merge> // This is the window
    <FrameLayout> // This is activity
            //A textview and 2 linearlayouts
    </FrameLayout>
</merge>

注意没有多余的FrameLayout。相反,它只是与活动的FrameLayout合并。只要有可能,就应该使用< merge> 。这不仅适用于FrameLayouts。你可以在这里读更多关于它的内容。 http://developer.android.com/training/improving- layouts / reusing-layouts.html#Merge

Notice how there is no extra FrameLayout. Instead, it is just merged with the FrameLayout of the activity. Whenever you can, you should use <merge>. This doesn't only apply to FrameLayouts. You can read more about it here. http://developer.android.com/training/improving-layouts/reusing-layouts.html#Merge

希望这会有所帮助。

这篇关于警告:此&lt; FrameLayout&gt;可以用&lt; merge&gt;替换标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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