0

enter image description here

I want to reuse top and bottom screen - only the Red part of the picture above. The middle white part, for each situation, I need to write XML.

But my app always has the same top-bottom view. I want to write once and reuse it.

Is it possible? How to solve this problem on android?

kahveci
  • 1,429
  • 9
  • 23
hyunwookcho
  • 65
  • 1
  • 6
  • 4
    Possible duplicate of [Android Layout: Is reusable component UI possible?](https://stackoverflow.com/questions/2289730/android-layout-is-reusable-component-ui-possible) – Vikasdeep Singh Jun 18 '18 at 08:26

1 Answers1

2

You have to add two xml layout name bottom and top, then you can use it in any layout you want,just add this code

<include layout="@layout/top" />
<include layout="@layout/bottom" />

this solution is useful for toolbar layout.

in bottom and top layout, write your code that you want reuse it.

Example:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<include layout="@layout/top" />

<ImageView
    android:id="@+id/your_dynamic_part"
    android:layout_width="wrap_content"
    android:layout_height="300dp" />

<include layout="@layout/bottom" />

</LinearLayout>
Fereshteh Naji
  • 104
  • 1
  • 11