これを達成する簡単な方法があります。
xmlファイルにインクルードタグがあり、1つのレイアウトを複数の画面デザインで使用できます。
たとえば。アプリケーションのヘッダーを作成したので、すべてのファイルで同じコードを使用する必要はありません。その部分を各 xml ファイルに含めることができます。
これはあなたを助けるかもしれない簡単な例です。
再利用可能なレイアウトを作成する
タイトルバー.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width=”match_parent”
android:layout_height="wrap_content"
android:background="@color/titlebar_bg">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/gafricalogo" />
</FrameLayout>
タグの使用:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:background="@color/app_bg"
android:gravity="center_horizontal">
<include layout="@layout/titlebar"/>
<TextView android:layout_width=”match_parent”
android:layout_height="wrap_content"
android:text="@string/hello"
android:padding="10dp" />
...
</LinearLayout>