This TableLayout layout or its LinearLayout parent

2019-07-04 05:45发布

I have tablelayout inside linearlayout but it shows me this warning message
This TableLayout layout or its LinearLayout parent is useless how to overcome from this warning can ane help me . Thanks in advance

<?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条回答
我命由我不由天
2楼-- · 2019-07-04 05:47

Through the warning, the system just wants to say you have the space to optimize your layout code.There is no need to care much about it if you do not want to optimize your code now.

查看更多
孤傲高冷的网名
3楼-- · 2019-07-04 05:52

If are looking for layout as below then the xml is as follows

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>
查看更多
祖国的老花朵
4楼-- · 2019-07-04 06:02

Remove the TableLayout tags and put the attributes into the TableRow tags.

查看更多
倾城 Initia
5楼-- · 2019-07-04 06:12

Why do you need top most LinearLayout when you dont have anything inside LinearLayout except TableLayout? One of these layout should be enough. Remove either LinearLayout (or) TableLayout. That should resolve the issue.

查看更多
登录 后发表回答