私は=>res/layout/item.xml
1つのレイアウトファイルをお持ちの場合:<include>タグoverride属性
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="60dp"
>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="John"
/>
<TextView
android:id="@+id/age"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:text="29" />
</LinearLayout>
そして、私は、コンテンツ上記項目のいくつか含まれて別のレイアウトファイルを持っている=>res/layout/main.xml
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:orientation="vertical"
>
<!--How can I override "name" and "age" attribute in the included item layout-->
<include android:id="@+id/student" layout="@layout/tem" />
<include android:id="@+id/teacher" layout="@layout/item" />
<include android:id="@+id/other" layout="@layout/item" />
</LinearLayout>
ますように上記を参照して、私は<include>
タグを使用して同じレイアウトを含める。しかし、「name
」と「age
」のテキスト値は、付属ののitem.xmlからmain.xmlに変更するにはどうすればよいですか?
。同じappの他のアクティビティで正確な 'item'レイアウトを再利用する予定がある場合にのみ' include'タグを使います。 – Luksprog
this http://stackoverflow.com/questions/2631614/does-android-xml-layouts-include-tag-really-work and this and this http://stackoverflow.com/questions/4801710/how-to-set-attributes -inside-android-layout-another-layoutに含まれている、つまりlayout_ *属性だけをオーバーライドすることができます –
"student"、 "teacher"、および "other"のすべてのレイアウトが同じであっても"アイテム、まだ使用できません?しかし、テキスト値だけが異なる同じレイアウトコードを繰り返し作成することを避ける方法はありますか? –