0
即時得到以下運行時錯誤:獲取RuntimeException:二進制XML文件行:您必須提供一個layout_width屬性。屬性缺失在哪裏?
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>