我收到以下运行时错误:
android.view.InflateException: Binary XML file line #24: Binary XML file line #15: You must supply a layout_width attribute.
我已经多次检查过我的代码,但我找不到任何我错过了layout_width属性的地方。问题在哪里?
item.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="@+id/myDate"/>
<TextView
android:layout_below="@id/myDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/myTime"/>
</RelativeLayout>
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.nirvan.recyclerview.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.nirvan.recyclerview.MainActivity"
tools:showIn="@layout/activity_main">
<android:android.support.v7.widget.RecyclerView
layout_height="match_parent"
layout_width="match_parent"
android:id="@+id/rv"/>
</RelativeLayout>
答案 0 :(得分:2)
<android:android.support.v7.widget.RecyclerView
layout_height="match_parent"
layout_width="match_parent"
android:id="@+id/rv"/>
应该是
<android:android.support.v7.widget.RecyclerView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/rv"/>