在Android中添加LinearLayout后,TableLayout不显示



一切都显示正常,直到我添加@+id/secondLayout。突然,在添加它之后,表格布局不再显示。什么好主意吗?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout 
android:id="@+id/secondLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
    <Chronometer
    android:id="@+id/chrono"
    android:textColor="#4169E1"
    android:textSize="20sp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Chronometer"
    />
</LinearLayout>
<TableLayout 
    android:id="@+id/parentLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/chrono"
>
</TableLayout>
</LinearLayout>

提前感谢您的时间。

android:layout_below="@id/chrono"LinearLayout中没有作用,因为它在RelativeLayout中使用。将TableLayout的权重设置为1,并将android:layout_height更改为"wrap_content"尝试以下数据:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/firstLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <LinearLayout
        android:id="@+id/secondLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >
        <Chronometer
            android:id="@+id/chrono"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Chronometer"
            android:textColor="#4169E1"
            android:textSize="20sp" />
    </LinearLayout>
    <TableLayout
        android:id="@+id/parentLayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="#123456"
        android:layout_weight="1" >
    </TableLayout>
</LinearLayout>

使用LinearLayoutTableLayout的高度为"wrap_content",因为子LinearLayout占用了父布局的空间。所以tablelayout没有显示。
即:试试这个布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout 
android:id="@+id/secondLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
    <Chronometer
    android:id="@+id/chrono"
    android:textColor="#4169E1"
    android:textSize="20sp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Chronometer"
    />
</LinearLayout>
<TableLayout 
    android:id="@+id/parentLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
>
</TableLayout>
</LinearLayout>

尝试将Chronometer高度更改为wrap_content

尝试使用

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/firstLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <LinearLayout
        android:id="@+id/secondLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <Chronometer
            android:id="@+id/chrono"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Chronometer"
            android:textColor="#4169E1"
            android:textSize="20sp" />
    </LinearLayout>
    <TableLayout
        android:id="@+id/parentLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/chrono" >
    </TableLayout>
</LinearLayout>

最新更新