此TableLayout布局或其LinearLayout父级如何解决此警告是无用的

时间:2012-01-18 05:45:03

标签: android layout

我在linelayout里面有tablelayout,但它向我显示了这条警告信息  此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>

4 个答案:

答案 0 :(得分:7)

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

答案 1 :(得分:1)

通过警告,系统只是想说你有空间来优化你的布局代码。如果你现在不想优化你的代码,就没有必要关心它。

答案 2 :(得分:1)

删除TableLayout标记并将属性放入TableRow标记。

答案 3 :(得分:0)

如果正在寻找如下布局,那么xml如下

Password_layout

<?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>