我在想,如果以下可以在XML來實現:是否有可能將視圖添加到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:layout_marginLeft="10dp"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Address: "
android:textSize="14dp" />
</LinearLayout>
當我有這個佈局在其他的XML,是可以添加其他的TextView中它,所以結果將如下所示:
地址:另一個textview的文本。
我想在xml中完成此操作,而不是通過編程方式。
我嘗試以下操作:
<include layout="@layout/mybaselayout" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="mylocalizedstring" />
</include>
這不工作,我會嘗試一些不可能在這裏XML做什麼?
謝謝。
如果我沒有弄錯,你應該可以把textview放在當前的下方。 – sbrichards 2012-07-31 06:36:33
然後,你應該添加textView到這個佈局......但我會說,以編程方式會更容易做到這一點。 – yahya 2012-07-31 06:36:39
但我有這樣的情況,就像有40個本地化的字符串用於第二個文本,但第一個文本總是相同的。所以我試圖使用更少的代碼。 – Niko 2012-07-31 06:41:20