【发布时间】:2015-02-26 12:41:33
【问题描述】:
我收到错误“必须声明元素 RelativeLayout”,但我不知道它发生的原因。如何摆脱此错误,请发布建议或代码 sn-ps。这是我的drawer_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/drawer_list_item"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@drawable/list_selector">
<ImageView
android:id="@+id/icon"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:contentDescription="@string/desc_list_item_icon"
android:src="@drawable/ic_launcher"
android:layout_centerVertical="true" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="@id/icon"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="@color/material_blue_grey_900"
android:gravity="center_vertical"
android:paddingRight="40dp"/>
<TextView android:id="@+id/counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/counter_bg"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="8dp"
android:textColor="@color/material_blue_grey_900"/>
</RelativeLayout>
【问题讨论】:
-
尝试干净构建或重新启动 eclipse 并检查您与 android SDK 工具的连接
-
尝试将你的RelativeLayout的id改为:android:id="@+id/drawer_list_item"
-
文件是否在
res/layout文件夹中? -
@programmer23 不工作兄弟
-
@Natix 是的,它在 res/layout 中