是否可以將參數傳遞給android中包含的佈局?例如,我想要在橫向模式下在水平LinearLayout中顯示一組按鈕,並使用相同的include將LinearLayout的方向更改爲「垂直」。Android在景觀和人像中重複使用佈局
<include layout="buttons.xml" orientation="horizontal"/>
在用於人像模式佈局XML我想這樣做:
<include layout="buttons.xml" orientation="vertical"/>
而在buttons.xml我會:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="doSomething"
android:text="foo" >
</Button>
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="doSomethingElse"
android:text="bar" >
</Button>
如果我正確解釋文檔只能覆蓋包含的佈局*屬性。
有沒有其他的方法/解決方法來做到這一點,而不重複佈局xml? 感謝您的意見!
嗨Mikel,在代碼中動態地改變佈局並不是我想到的。我正在尋找一種方法來做到這一點在XML中。我知道資源選擇器可以覆蓋特定的佈局資源,但我擔心使用選擇器總是會產生冗餘資源,這些資源在以後很難維護。任何其他想法/提示? – markus