Это похоже на простой вопрос, который я могу найти легко, но у меня возникли проблемы с пониманием того, как создать многоразовый компонент пользовательского интерфейса для Android. В частности, я пытаюсь создать этот фрагмент, который я использую EVERYWHERE в компоненте многократного использования, чтобы сделать код меньше.Как создать многократно используемый компонент пользовательского интерфейса
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="0dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textColor="@color/text_normal"
android:id="@+id/my_text_id"
android:text="My field"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textColor="@color/text_normal"
android:text="My value"
android:id="@+id/my_value_id"/>
</RelativeLayout>
Они используются как этот
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/background_normal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="0dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textColor="@color/text_normal"
android:id="@+id/my_text_id"
android:text="My field"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textColor="@color/text_normal"
android:text="My value"
android:id="@+id/my_value_id"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="0dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textColor="@color/text_normal"
android:id="@+id/my_text_id2"
android:text="My field2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textColor="@color/text_normal"
android:text="My value2"
android:id="@+id/my_value_id2"/>
</RelativeLayout>
.... etc ....
</LinearLayout>
</ScrollView>
Я надеюсь, чтобы иметь возможность получить доступ к обеим текстовым полям для присвоения значений внутри, которые будут добавлены с <include />
тегом макета. Кто-нибудь знает как это сделать?
Я видел http://developer.android.com/resources/articles/layout-tricks-reuse.html, но, похоже, я не вижу, как назначить несколько одинаковых полей.
Любая помощь приветствуется.
Обновление Они используются для размещения TextView слева от экрана, а другой справа выстроены вместе. Не знаете, как это описать, но они используются в ScrollView.
, где вы хотите повторно использовать этот макет точно? для заголовка или еще? –
Обновлено описание – Kirk