2012-08-04 63 views
8

我覺得這個問題以前一定要問過,但是我找不到。如何爲Android XML佈局屬性使用多個值?

我想有一個LinearLayout這樣一切都對齊到右邊和底部。

我已經試過:

android:gravity="right | bottom" 
    android:gravity="right + bottom" 
    android:gravity="right & bottom" 
    android:gravity="right, bottom" 
    android:gravity="right bottom" 

所有這些生產

Error: String types not allowed (at 'gravity' with value 'right, bottom'). 

我想我可以在子元素使用的空間,但我寧願不要。

回答

18

Grah。這是空間。正確的語法是

android:gravity="right|bottom" 

我希望Eclipse會有這樣的建議,如果它看到你輸入一個字符串。像

Error: String types not allowed (at 'gravity' with value 'right, bottom'). 
If you want to enter multiple values, use the syntax "value1|value2" 
+0

太棒了,我正在尋找這個答案。 – Matt 2013-01-14 13:44:40

+1

是的,這是我想要的,通過刪除空白後。 – 2014-10-25 02:33:15

+1

稍後反思這一點,我發現對String類型的引用不被允許可能是因爲這是一個整數,或者在'value1 | value2'的情況下,兩個整型標記與'OR '操作員。但目前還不清楚爲什麼空間應該讓它死亡。 – MalcolmOcean 2015-02-02 11:59:25