【问题标题】:This TableLayout layout or its LinearLayout parent is useless how to resolve from this warning此 TableLayout 布局或其 LinearLayout 父级无用如何解决此警告
【发布时间】:2012-07-24 05:46:13
【问题描述】:

我在线性布局中有表格布局,但它向我显示了这条警告消息
这个 TableLayout 布局或者它的 LinearLayout 父级是没用的 如何克服这个警告可以帮助我。 在此先感谢

<?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent" >

          <TableLayout>

            <TableRow
                android:id="@+id/tableRow3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center" >

                <TextView
                    android:id="@+id/txtPass"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical|center_horizontal"
                    android:text="Password"
                    android:textSize="18sp"
                    android:width="100dp" />

                <EditText
                    android:id="@+id/edPass"
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:inputType="textPassword"
                    android:password="true" >

                    <requestFocus />
                </EditText>
              </TableRow>
          </TableLayout>

      </LinearLayout>

【问题讨论】:

    标签: android layout


    【解决方案1】:

    当你在 LinearLayout 中除了 TableLayout 之外没有任何东西时,为什么你需要最顶层的 LinearLayout?这些布局之一就足够了。删除 LinearLayout(或)TableLayout。这应该可以解决问题。

    【讨论】:

    • 现在我有了这个布局 schemas.android.com/apk/res/android" android:id="@+id/ tableLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" > 和里面的
    • 应该可以。你还在收到那个警告信息吗?
    • 实际上我想要一个像登录页面这样的视图,但我希望它位于活动的中心,所以我该如何实现这一点,请帮助我。
    • 您确定 XML 文件中没有 LinearLayout 对吗?如果是这样,请清理项目。关闭文件并再次打开。
    • 您可能需要使用RelativeLayout。这是带有示例的链接。 wowjava.wordpress.com/2011/01/16/login-application-for-android
    【解决方案2】:

    通过警告,系统只是想说你有空间优化你的布局代码。如果你现在不想优化你的代码,不需要太在意。

    【讨论】:

    • 不过,注意警告是个好习惯——它们通常是有道理的!在这种情况下,两种布局都是不必要的,所以应该删除一个。
    【解决方案3】:

    去掉 TableLayout 标签,将属性放入 TableRow 标签中。

    【讨论】:

      【解决方案4】:

      如果正在寻找如下布局,则 xml 如下

      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="horizontal" 
          android:gravity="center">
      <TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Password" />
      <EditText
              android:layout_marginLeft="5dp"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:hint="Password" />
      
      
      </LinearLayout>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-14
        • 1970-01-01
        相关资源
        最近更新 更多