视图不会显示在相对布局中

时间:2014-06-12 11:35:03

标签: android view relativelayout

我的布局有问题,我无法找出问题所在。 正如您所看到的,相对布局中有一个天文台和一个桌子,但是天文台没有显示,甚至没有空白。

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

任何想法?

4 个答案:

答案 0 :(得分:1)

您的TableLayout占用了所有空间(match_parent)并覆盖ChronometerRelativeLayout孩子被安排,以便他们被宣布。我不知道你想要什么,但你可以先从布局中切换两个的顺序,以便Chronometer覆盖TableLayout

答案 1 :(得分:0)

首先将Chronometer粘贴到底部android:layout_alignParentBottom="true",然后在TableLayout

上方Chronometer
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/firstLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TableLayout
        android:id="@+id/parentLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/chrono" >
    </TableLayout>

    <Chronometer
        android:id="@+id/chrono"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="Chronometer"
        android:textColor="#4169E1"
        android:textSize="20sp" />

</RelativeLayout>

答案 2 :(得分:0)

试试这个......这肯定会解决你的问题..

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/firstLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<Chronometer
    android:id="@+id/chrono"
    android:textColor="#4169E1"
    android:textSize="20sp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
   android:layout_alignParentTop="true"
    android:text="Chronometer"
/>

<TableLayout 
    android:id="@+id/parentLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/chrono"
    >
</RelativeLayout>

答案 3 :(得分:0)

最后我得到了显示天文台的方法。 感谢所有试图帮助我的人,答案非常接近我的解决方案:

<Chronometer
android:id="@+id/chrono"
android:textColor="#4169E1"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Chronometer"
/>
<TableLayout 
android:id="@+id/parentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/chrono"
>
相关问题