I try to set this as the layout of my activity:
<?xml version="1.0" encoding="utf-8"?>
<include layout="@layout/map_activity_base" />
If I use @layout/map_activity_base
instead of including it, it works. The reaseon why I don't do that is because you can't include content of layouts for small screens in layouts for large screens but I need the content of @layout/map_activity_base
in different layouts.
The Error I get is
E/AndroidRuntime(11383): FATAL EXCEPTION: main
E/AndroidRuntime(11383): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.l_one.app.achileo/de.l_one.app.achileo.Main}: android.view.InflateException: Binary XML file line #2: Error inflating class include
[...]
E/AndroidRuntime(11383): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class include
[...]
E/AndroidRuntime(11383): Caused by: java.lang.ClassNotFoundException: android.view.include in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/de.l_one.app.achileo-1.apk]
So it seems that android thinks <include />
is supposed to be a View
but that only happens if I use <include />
without any surrounding View
So is it possible to use <include />
without any surrounding View
and if not what is the best way to achieve what I want?
Btw: I don't know if it matters but this is the content of a library project.
edit: map_activity_base.xml
<?xml version="1.0" encoding="UTF-8" ?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView android:id="@+id/listHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="@string/listHeader"
android:padding="5dp" />
<View android:id="@+id/divider"
android:layout_width="100dp"
android:layout_height="1dp"
android:background="#333"
android:layout_below="@id/listHeader" />
<de.l_one.app.map.base.POIListView android:id="@+id/poiList"
android:layout_width="100sp"
android:layout_height="match_parent"
android:divider="#cccccc"
android:dividerHeight="1dp"
android:layout_alignParentLeft="true"
android:layout_below="@id/divider"
android:listSelector="@android:color/transparent" />
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@id/poiList"
android:clickable="true"
android:apiKey="@string/googleAPIKey" />
<TextView android:id="@+id/cmtryNameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:padding="5dp"
android:background="@drawable/cmtry_txt_view_back" />
<TextView android:id="@+id/navigate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/cmtryNameTextView"
android:padding="5dp"
android:background="@drawable/cmtry_txt_view_back"
android:visibility="gone"
android:text="@string/navigate" />
</RelativeLayout>
I believe you need put "include" inside the root view at least. Something like following:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
...
<include layout="@layout/titlebar"/>
...
/>
It looks like <include/>
can't be defined at the root of the layout. If you really need to start with an include, a better way is to use a <merge/>
:
file fragment_map.xml
<?xml version="1.0" encoding="utf-8"?>
<!--
the <merge/> tag must be the root element
while it actually defines an xml include.
-->
<merge
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- insert some layout here -->
</merge>
file activity_map.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- then the <include/> tag can then reference it, while merging. -->
<include
layout="@layout/fragment_map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.design.widget.CoordinatorLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With