一切都显示正常,直到我添加@+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>
使用LinearLayout
和TableLayout
的高度为"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>