Android 此TableLayout布局或其LinearLayout父级对于如何解决此警告无效

Android 此TableLayout布局或其LinearLayout父级对于如何解决此警告无效,android,layout,Android,Layout,我在linearlayout中有tablelayout,但它显示了此警告消息 此TableLayout或其LinearLayout父级无效 如何克服这个警告可以帮助我。 提前谢谢 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="m

我在linearlayout中有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>


除了表格布局,线性布局中没有任何内容,为什么需要最上面的线性布局?其中一个布局就足够了。删除LinearLayout(或)TableLayout。这应该可以解决问题。

如果您正在寻找如下布局,那么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>



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

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

现在我有了这个应该可以工作的布局。你仍然收到警告消息吗?实际上我想要一个类似登录页面的视图,但我希望它位于活动中心,因此我如何才能获得此plz帮助我。你确定你没有XML文件中的LinearLayout,对吗?如果是,请清理项目。关闭文件并再次打开。您可能需要使用RelativeLayout。下面是与示例的链接。不过,注意警告是一个很好的做法——它们通常是有道理的!在这种情况下,两种布局都是不必要的,因此应该删除一种布局。