2011-04-15 90 views
1

我有一個佈局,看起來像這樣背景圖像會導致第二線性佈局消失

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    style="@style/Splash"> 

    <TextView android:id="@+id/splash_title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     style="@style/Splash.H1" 
     android:text="@string/splash_title"/> 

    <LinearLayout android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:orientation="horizontal"> 

    <ImageView 
     android:id="@+id/splash_image" 
     android:src="@drawable/ic_launcher_ftnicon" 
     style="@style/Splash.Image"/> 

    <TextView android:id="@+id/splash_powered_by" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     style="@style/Splash.H2" 
     android:text="@string/splash_powered_by"/> 
</LinearLayout> 

</LinearLayout> 

我的風格是這樣的

<style name="Splash"> 
    <item name="android:gravity">center</item> 
    <item name="android:background">#FFFFFF</item> 
</style> 

當我改變的背景下被拉伸,就像這樣:

<style name="Splash"> 
    <item name="android:gravity">center</item> 
    <item name="android:background">@drawable/bg_splash</item> 
</style> 

第二個線性佈局完全消失。背景圖片顯示並顯示標題的文本視圖。

+0

是否有助於記住,如果將背景圖像設置爲包裝其內容的視圖,其最小尺寸將是背景圖像的最小尺寸? – bigstones 2011-04-15 19:46:23

+0

我不認爲這真的對此產生影響,因爲所討論的文本都使用中心重力。根linearlayout內部的文本應該在中間,但其他線性佈局甚至沒有顯示。 – Josh 2011-04-15 19:48:24

+0

您是否嘗試過使用Hierarchy Viewer查看內部佈局會發生什麼? – bigstones 2011-04-15 20:04:57

回答

1

這是我認爲正在發生的事情。

Your @ drawable/bg_splash是一個全屏圖像。

請記住,對於樣式,所有孩子都將繼承父級的設置(即Splash.H1也將具有與Splash相同的背景)。這意味着所有視圖的背景將被設置爲相同的全屏圖像。按照您定義的方式進行佈局,唯一顯示的視圖是「@ + id/splash_title」文本視圖。線性佈局將被強制離開屏幕底部。