包括

2016-08-02 61 views
0

時如何重寫子佈局的佈局PARAMS比方說,我有my_custom_view.xml包括

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"> 
    <TextView android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/hello" 
       android:padding="10dp" /> 

    ........ 
</LinearLayout> 

而且我想包括我的activity_main.xml多次my_custom_view

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"> 

    <include layout="@layout/my_custom_view.xml"/> 
    <include layout="@layout/my_custom_view.xml"/> 
    <include layout="@layout/my_custom_view"/> 
</LinearLayout> 

但是如果我只想覆蓋每個my_custom_view意見文本(TextView的)。

ie與<include/>標籤一起使用時,如何覆蓋父my_custom_view.xml的子元素的參數?

我知道我可以創建一個具有屬性的自定義視圖類,但是我希望我的視圖能夠直接在Android Studios設計視圖上呈現。

回答

0

你不能在xml中真正做到這樣的複雜邏輯。

自定義視圖像其他視圖一樣呈現(只是在創建類之後重建項目)。如您已經知道的,它們還爲attrs.xml提供了更多的靈活性