2014-06-12 34 views
-5

我有這個佈局的問題,我找不到什麼是錯的。 正如你所看到的,在相對佈局內部有一個天文臺和一張桌子,但是天文臺並沒有顯示,甚至沒有空白空間。一個視圖不顯示在相對佈局裏

<?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> 

有什麼想法嗎?

+0

讓你的表格佈局高度WRAP_CONTENT –

+0

只需更改爲最後聲明Chronometer'的'位置,我的意思是先寫'TableLayout'然後'Chronometer' –

+0

謝謝大家的建議,但我相信這個問題是在別的地方,因爲我嘗試了所有你說的,但沒有。 我發佈了一個新的話題與問題.http://stackoverflow.com/questions/24201301/view-not-showing-in-a-relative-layout-in-android – iversoncru

回答

1

您的TableLayout佔據了所有空間(match_parent)並吸引了ChronometerRelativeLayout爲了宣佈他們的孩子,他們被安排好了。我不知道你想要的是什麼,但是你可以從佈局中切換兩者的順序開始,以便Chronometer可以覆蓋TableLayout

+0

什麼我應該使用「layout_height」的TableLayout?謝謝 – iversoncru

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> 
0

嘗試......這將definitly解決您的問題..

<?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> 
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" 
> 
相關問題