2013-01-02 63 views
0

是否有可能在標籤中覆蓋xml中的屬性?覆蓋xml <include ... />

parent.xml

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
    <include 
     layout="@layout/button" 
     android:text="HAHAHAH" 
     /> 
</TableLayout> 

button.xml:

<?xml version="1.0" encoding="utf-8"?> 
    <TextView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="some string" /> 

是否有可能改變 「一些字符串」 到 「哈哈哈」?

+0

什麼是你的終極目標是什麼? –

+0

與java中的抽象類相似。按鈕只是一個容器,然後在父母我填寫一些細節。 – wtsang02

回答

2

是的,沒有:)「是」,因爲你可以在一般的重寫XML屬性,「否」,因爲在這種情況下,只有改變android:layout_* attribues生效:

您還可以覆蓋所有的佈局參數(任何android:layout_* 屬性),通過在 標籤中指定包含佈局的根視圖。例如:爲了layout_width其他佈局屬性採取 效果:

<include android:id=」@+id/news_title」 
     android:layout_width=」match_parent」 
     android:layout_height=」match_parent」 
     layout=」@layout/title」/> 

但是,如果要覆蓋使用 標籤佈局屬性,則必須同時覆蓋Android版本:layout_height和 機器人。

http://developer.android.com/training/improving-layouts/reusing-layouts.html#Include