【问题标题】:How to fix Android warning - FrameLayout layout or its LinearLayout parent is useless如何修复 Android 警告 - FrameLayout 布局或其 LinearLayout 父级无用
【发布时间】:2014-07-26 18:31:57
【问题描述】:

我的 Android 项目中的特定视图出现警告。 这是什么意思?如何解决?

第 10 行警告:“FrameLayout”

这个 FrameLayout 布局或者它的 LinearLayout 父级是没用的;将背景属性转移到另一个视图 Android Lint 问题

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/stepLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/paper"
    android:orientation="vertical" >

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <ImageView
            android:id="@+id/example_image"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:contentDescription="@string/descExample" />

        <ImageButton
            android:id="@+id/buttonNext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right|bottom"
            android:layout_margin="5dip"
            android:background="@android:color/transparent"
            android:contentDescription="@string/descButtonNext"
            android:padding="5dip"
            android:src="@drawable/nav_next_40"
            android:text="@string/buttonNext" />

        <ImageButton
            android:id="@+id/buttonPrevious"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left|bottom"
            android:layout_margin="5dip"
            android:background="@android:color/transparent"
            android:contentDescription="@string/descButtonPrevious"
            android:padding="5dip"
            android:src="@drawable/nav_previous_40"
            android:text="@string/buttonPrevious" />

        <ImageButton
            android:id="@+id/buttonHome"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center|bottom"
            android:layout_margin="5dip"
            android:background="@android:color/transparent"
            android:contentDescription="@string/descButtonHome"
            android:padding="5dip"
            android:src="@drawable/nav_home_40"
            android:text="@string/buttonHome" />

        <ImageButton
            android:id="@+id/buttonShare"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right|bottom"
            android:layout_margin="5dip"
            android:background="@android:color/transparent"
            android:contentDescription="@string/descButtonShare"
            android:padding="5dip"
            android:src="@drawable/nav_share_40"
            android:text="@string/buttonShare" />
    </FrameLayout>

</LinearLayout>

【问题讨论】:

  • Dimitri,也就是说,你只在FrameLayout里面声明了你的所有属性,所以不需要LinearLayout,你的主要LinearLayout什么也没做,所有的东西都在做FrameLayout,这就是你得到它的原因警告。
  • 移除LinearLayout并将FrameLayout设为父Layout。LinearLayout适用于多个子视图。但对你来说它只有一个子
  • 简化你的布局,为了表演!通过简化进行优化。

标签: android layout warnings


【解决方案1】:

真的需要 LinearLayout 吗?

如果不只是将 android:background、xmlns:android 和 android:id 移动到 FrameLayout 并删除 LinearLayout 及其结束标记。此外,从您的代码来看,您似乎从未在代码中使用过 xmlns:ads,因此您也可以删除该行。

保持简单。

【讨论】:

    【解决方案2】:

    这只是一个警告。如果您绝对需要这两种布局,则可以忽略该警告。但最好不要忽略警告并删除不需要的布局。此警告会影响您应用的性能。查看此 SO post 了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-11
      • 1970-01-01
      • 2012-07-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多