2013-03-26 75 views
0

我試圖設置背景到RelativeLayout。 問題在於佈局在圖像大小之後調整大小,這是我不想要的。我希望佈局在兩個文本瀏覽後進行大小調整。防止佈局調整後背景

無論如何,以防止佈局縮放到背景的大小?

這是XML的代碼

<RelativeLayout 
    android:id="@+id/hud" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@+drawable/hud_background" 
    android:layout_weight="1" > 

    <TextView 
     android:id="@+id/lblScore" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:text="Score: " /> 

    <TextView 
     android:id="@+id/txtScore" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBaseline="@+id/lblScore" 
     android:layout_alignBottom="@+id/lblScore" 
     android:layout_toRightOf="@+id/lblScore" 
     android:text="00" /> 

</RelativeLayout> 

問候

+0

能否請您再字呢? 「你的意思是」現在發生的圖像大小之後,佈局不應該調整大小?「 – yarian 2013-03-26 20:47:30

+0

希望它現在更清晰一點 – Fredkr 2013-03-26 20:54:41

+0

ouuh你的意思是相對佈局高度應該是textview1高度+ textview2高度,無論背景圖像大小..? – lelloman 2013-03-26 20:56:49

回答

1

我認爲,所有你需要的是改變的android:layout_width = 「match_parent」 成機器人:layout_width =爲RelativeLayout的 「WRAP_CONTENT」,所以大小將根據textViews單獨。

爲什麼添加android:layout_weight =「1」?它只是你的佈局文件的一部分?

如果是這樣,如果它在一個垂直的LinearLayout,用途:

android:layout_width="match_parent" 
android:layout_height="0px" 

,如果它是在一個水平LinearLayout中,使用:

android:layout_width="wrap_content" 
android:layout_height="0px" 
+0

是它的垂直線性佈局的一部分,我只是想出了這一點以及:)謝謝! – Fredkr 2013-03-26 21:20:31