Я пытаюсь превратить пару кнопок в компонент многократного использования в Android. Я успешно получил часть XML/UI, но я не могу понять, как сделать код за ним многократно используемым, не переписывая его везде. Я новичок в Android, поэтому прошу прощения, если это очевидно.
Я уже несколько раз пересматривал этот пост: Android layout Tricks 3 - Part 1, но, похоже, отсутствует несколько файлов, и У меня недостаточно опыта для их восстановления.
Отброшенная версия моего основного макета:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="375px"
android:layout_alignParentTop="true" />
<include layout="@layout/navbar"/>
</RelativeLayout>
а затем моего "компонента":
<?xml version="1.0" encoding="UTF-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center">
<ImageButton android:id="@+id/Button1"
android:layout_width="71px"
android:layout_height="wrap_content"
android:background="@drawable/button1"
android:layout_alignParentBottom="true" />
<ImageButton android:id="@+id/Button2"
android:layout_width="75px"
android:layout_height="wrap_content"
android:background="@drawable/button1"
android:layout_toRightOf = "@+id/Button1"
android:layout_alignParentBottom="true" />
</LinearLayout>
</merge>
Если у вас есть какие-либо дополнительные критические замечания по моему XML, я тоже признателен.