天天看點

Android在layout xml中使用include[轉]

在Android的layout樣式定義中,可以使用xml檔案友善的實作,有時候為了子產品的複用,使用include标簽可以達到此目的。例如:

其中,有提到:

Similarly, you can override all the layout parameters. This means that any android:layout_* attribute can be used with the <code>&lt;include&gt;</code> tag. 意思是任何android:layout_*屬性都可以應用在标簽中。

如果使用如下代碼:

發現<code>include</code>的otherlayout,并沒有在如我們預期的在id/top這個TextView下面,而是忽略了android:layout_below屬性。經過Google發現,很多人遇到類似的問題。

有解決方法是在include的外面再包一層LinearLayout,如下:

解答道:必須同時重載layout_width和layoutheight熟悉,其他的layout*屬性才會起作用,否這都會被忽略掉。上面的例子應該寫成這樣:

from:http://www.race604.com/using-include-in-layout/

歡迎加群互相學習,共同進步。QQ群:iOS: 58099570 | Android: 572064792 | Nodejs:329118122 做人要厚道,轉載請注明出處!

本文轉自張昺華-sky部落格園部落格,原文連結:http://www.cnblogs.com/sunshine-anycall/p/4819049.html,如需轉載請自行聯系原作者

繼續閱讀