2010-04-04 81 views
4

我在Android 1.5上的RelativeLayout中出現視圖重疊的問題...在Android 1.6及更高版本上,一切正常。Android 1.5上的RelativeLayout與視圖重疊

我明白Android 1.5有一些與RelativeLayout相關的問題,但我無法在StackOverflow或Android初學者組中找到任何有關我的特定問題的信息。

我的佈局由四個部分組成,其中的每一個都是由一個TextView,一個畫廊,和另一TextView的垂直對齊:

正在運行的應用
最近訪問的應用
服務
過程

當所有四組這些項目都顯示一切正常。但是,我的應用程序允許用戶指定其中的一些不顯示。如果用戶關閉運行應用程序,最近的應用程序或服務,則其餘部分突然彼此重疊。

這是我的佈局代碼。我不知道我做錯了什麼。當用戶關閉一個區間的顯示我用的是View.GONE可見性設置:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="center_vertical" 
    android:layout_gravity="center_vertical" 
    android:background="@null" 
> 
<!-- Running Gallery View Items --> 
<TextView 
    style="@style/TitleText" 
    android:id="@+id/running_gallery_title_text_id" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="left" 
    android:paddingLeft="1sp" 
    android:paddingRight="10sp" 
    android:text="@string/running_title" 
/> 

<Gallery 
    android:id="@+id/running_gallery_id" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/running_gallery_title_text_id" 
    android:spacing="5sp" 
    android:clipChildren="false" 
    android:clipToPadding="false" 
    android:unselectedAlpha=".5" 
/> 

<TextView 
    style="@style/SubTitleText" 
    android:id="@+id/running_gallery_current_text_id" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/running_gallery_id" 
    android:gravity="center_horizontal" 
/> 

<!-- Recent Gallery View Items --> 
<TextView 
    style="@style/TitleText" 
    android:id="@+id/recent_gallery_title_text_id" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/running_gallery_current_text_id" 
    android:gravity="left" 
    android:paddingLeft="1sp" 
    android:paddingRight="10sp" 
    android:text="@string/recent_title" 
/> 

<Gallery 
    android:id="@+id/recent_gallery_id" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/recent_gallery_title_text_id" 
    android:spacing="5sp" 
    android:clipChildren="false" 
    android:clipToPadding="false" 
    android:unselectedAlpha=".5" 
/> 

<TextView 
    style="@style/SubTitleText" 
    android:id="@+id/recent_gallery_current_text_id" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/recent_gallery_id" 
    android:gravity="center_horizontal" 
/> 

<!-- Service Gallery View Items --> 
<TextView 
    style="@style/TitleText" 
    android:id="@+id/service_gallery_title_text_id" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/recent_gallery_current_text_id" 
    android:gravity="left" 
    android:paddingLeft="1sp" 
    android:paddingRight="10sp" 
    android:text="@string/service_title" 
/> 

<Gallery 
    android:id="@+id/service_gallery_id" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/service_gallery_title_text_id" 
    android:spacing="5sp" 
    android:clipChildren="false" 
    android:clipToPadding="false" 
    android:unselectedAlpha=".5" 
/> 

<TextView 
    style="@style/SubTitleText" 
    android:id="@+id/service_gallery_current_text_id" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/service_gallery_id" 
    android:gravity="center_horizontal" 
/> 
</RelativeLayout> 

我ommitted在一個(有點徒勞的)嘗試進程部分XML保持這個短...

我能做些什麼才能在Android 1.5中實現這個功能?我不認爲這只是在xml中對視圖進行重新排序的問題,因爲在顯示所有內容時它可以正常工作。

回答

4

兩個可能的解決方案:

  • 嘗試元素的高度爲0或1 PX和知名度設置爲不可見,而不是消失。
  • 將LinearLayout中的每個圖庫/文本視圖設置爲wrap_height,並在佈局上設置上方/下方而不是子視圖。然後將子元素設置爲View.GONE,留下用於相對定位的線性佈局仍然可見,但是包裝高度爲0.

這兩種解決方案的想法都是確保您永遠不會定位相對於這是View.GONE;我懷疑這是你遇到的錯誤的來源。

如果我可能會問,雖然......爲什麼你甚至需要在這裏使用RelativeLayout呢?從我一眼就能看到的情況來看,這裏的所有東西都可以很好地適用於垂直LinearLayout,事實上這種安排在概念上似乎更簡單。

+0

感謝您的建議...我會給他們一個嘗試。 這是我對縱向模式的佈局...使用橫向模式會變得更復雜一些,並且需要幾個嵌套的LinearLayout。雖然我可以在縱向模式下使用LinearLayout,但對於橫向模式仍然存在相同的問題。 – Justin 2010-04-04 20:01:44