2013-08-07 49 views
0

單擊按鈕時,我需要分離gmt_option_list_dst_off.xml並在<include>標記中附加新佈局gmt_option_list_dst_on.xml如何通過編程方式在<include>中添加新佈局

以下是XML文件:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:weightSum="6" > 

    <include 
     android:id="@+id/gmt_optionlist" 
     android:layout_weight="5" 
     layout="@layout/gmt_option_list_dst_off" /> 

    <Button 
     android:id="@+id/dstbutton" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="DST Off" > 
    </Button> 

</LinearLayout> 

推薦我,這是可能的,附加新的佈局,包括在運行時的標籤。

我已經經歷了幾個後消失了,目前我使用

parentOfAllInGMT.addView(layoutInflater.inflate(R.layout.gmt_option_list_dst_on, parentOfAllInGMT, true), 0); 

,但這是不正確的。

+0

我建議你應該使用這樣的LineaerLayout:http://stackoverflow.com/questions/8589880/how-can-i-change-included -xml佈局到另一個佈局上的Java代碼 –

回答

0

使用addView()和removeViewAt呼籲含有包括標籤

0

試試這個,它應該做的伎倆:

ViewStub stub = (ViewStub) findViewById(R.id. gmt_optionlist); 
stub.inflate(); 

希望這有助於。

相關問題