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

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

问题描述

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

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 可以替换为 <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.以下是放置布局文件之前 Activity 的布局.

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?拥有它是多余的,因为它没有增加太多价值.要优化,您可以使用 标记替换 outer FrameLayout.这就是它的样子.

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 合并.只要有可能,就应该使用 .这不仅适用于 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天全站免登陆