Я пытаюсь унифицировать свои макеты и поэтому хочу повторно использовать некоторые элементы пользовательского интерфейса.Если я пытаюсь включить эти элементы в мой main.xml , приложение вылетает с
02-15 13: 07: 02.470: E / AndroidRuntime (16588): вызвано:java.lang.RuntimeException: строка двоичного XML-файла # 2: Вы должны предоставить атрибут layout_width.
Мой XML выглядит как
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLL"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<include layout="@layout/include_topbar"/>
</LinearLayout>
<!-- include_topbar -->
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout style="@style/topbar_linearlayout">
<include layout="@layout/include_icon"/>
<include layout="@layout/include_topbar_title"/>
</LinearLayout>
</merge>
<!-- include_icon -->
<merge xmlns:android="schemas.android.com/apk/res/android">
<View
android:background="@drawable/icon"
android:layout_width="48dp"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
/></merge>
<!-- include_topbar_title -->
<merge xmlns:android="schemas.android.com/apk/res/android">
<TextView
android:gravity="center"
android:text="@string/bla"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
/></merge>
<!-- topbar_linearlayout -->
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="topbar_linearlayout">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">58dp</item>
<item name="android:padding">5dp</item>
<item name="android:orientation">horizontal</item>
<item name="android:background">@drawable/gradient_background</item>
</style>
</resources>
Редактировать: Не использовать <merge>
тогда будет работать ...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/topbar_linearlayout">
<include layout="@layout/include_icon"/>
<include layout="@layout/include_topbar_title"/>
</LinearLayout>
<!-- include_icon -->
<View xmlns:android="schemas.android.com/apk/res/android"
android:background="@drawable/icon"
android:layout_width="48dp"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
/>