Android: Geben Sie ein XML in einen anderen XML ein
-
26-10-2019 - |
Frage
So fügen Sie eine XML -Daten in eine andere XML -Daten ein
Ich habe ein Header XML-Datei für meine Anwendung, die ich in meinem speziellen anderen Inhalt verwenden möchte.
Lösung
Verwenden Sie inklusive Tag
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!-- Header -->
<include
android:id="@+id/container_header_lyt"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_above=...
android:layout_toLeftOf=...
layout="@layout/header_logo_lyt" //Name of the xml layout file you want to include
/>
...
</RelativeLayout>
Andere Tipps
Sie müssen Ihr "Body" XML -Layout mit einem <Merge> -Tag für Ihr Hauptlayout für <Cläder einfügen.
<?xml version="1.0" encoding="utf-8"?>
<merge>
<ImageView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"
android:src="@drawable/image" / >
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:background="#AA000000"
android:textColor="#ffffffff"
android:text="Some Text" / >
</merge>
Dies ist der Inhalt Ihres <Clemit> -Tags
Sie sollten <Clemit> Tag verwenden: Wiederverwenden von Layouts mit
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow