二进制XML文件行#14:您必须提供layout_width属性

时间:2017-02-24 10:38:09

标签: android layout

我正在使用calendarview和drawerlayout,我发现了这个错误。

我的布局是:

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

    <include
        android:id="@+id/tool_bar_dashboard"
        layout="@layout/toolbar" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:baselineAligned="false"
        android:orientation="horizontal">

        <android.support.v4.widget.DrawerLayout
            android:id="@+id/drawer_layout"
            android:layout_width="276dp"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <ListView
                android:id="@+id/list_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:choiceMode="singleChoice"
                android:divider="@android:color/transparent"
                android:dividerHeight="0dp"/>
        </android.support.v4.widget.DrawerLayout>

        <LinearLayout
            android:id="@+id/calendar1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"/>
    </LinearLayout>
</LinearLayout>

我不知道错误是什么,我尝试将所有layout_witdth属性更改为其他值,但错误不会消失。

我的工具栏布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimaryDark"></android.support.v7.widget.Toolbar>

编辑:最后我找不到错误。所以我不得不回到我的应用程序的其他版本,它很好,但两个版本都有相同的代码。我不明白。

2 个答案:

答案 0 :(得分:0)

在覆盖 id 属性时,您必须指定高度和宽度。

请参阅 include tag

的官方链接
  

但是,如果要使用。覆盖布局属性   标签,你必须覆盖android:layout_height和   android:layout_width,以便采取其他布局属性   效果。

所以你的标签变得像

<include android:id="@+id/tool_bar_dashboard"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         layout="@layout/toolbar"/>

答案 1 :(得分:-1)

只需在样式中添加wrap_content而不是match_parent

 <style name="EstiloBase">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:orientation">horizontal</item>

</style>