單擊按鈕時,我需要分離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);
,但這是不正確的。
我建議你應該使用這樣的LineaerLayout:http://stackoverflow.com/questions/8589880/how-can-i-change-included -xml佈局到另一個佈局上的Java代碼 –