加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

关于自定义控件在布局文件中使用时提示error: Error parsing XML

发布时间:2020-12-16 06:13:45 所属栏目:百科 来源:网络整理
导读:今天在尝试自定义一个控件后,在布局文件中使用的时候报错 RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:carrey="http://schemas.android.com/apk/res/com.example.cu

今天在尝试自定义一个控件后,在布局文件中使用的时候报错

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:carrey="http://schemas.android.com/apk/res/com.example.customview"
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"
tools:context=".MainActivity" >


<com.carrey.customview.CustomView
android:id="@+id/customview"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerInParent="true"
android:background="#FFD700"
carrey:imageAlpha="0.5"
carrey:imageAspectRatio="1.0"
carrey:imagePaddingBottom="5dp"
carrey:imagePaddingLeft="5dp"
carrey:imagePaddingRight="5dp"
carrey:imagePaddingTop="5dp"
carrey:imageScaleType="center"
carrey:imageSrc="@drawable/b_fuzhuang01"
carrey:subTitlePaddingBottom="3dp"
carrey:subTitlePaddingLeft="3dp"
carrey:subTitlePaddingRight="3dp"
carrey:subTitlePaddingTop="3dp"
carrey:subTitleText="这是二级子标题"
carrey:subTitleTextColor="#00FF7F"
carrey:subTitleTextSize="20sp"
carrey:titlePaddingBottom="4dp"
carrey:titlePaddingLeft="4dp"
carrey:titlePaddingRight="4dp"
carrey:titlePaddingTop="4dp"
carrey:titleText="这是一级标题"
carrey:titleTextColor="#1E90FF"
carrey:titleTextSize="30sp" />
</RelativeLayout>

提示在引用自定义控件的时包名处提示错误error: Error parsing XML: not well-formed (invalid token)。纠结了很久才解决的。可能有两个原因,一个是xmlns:carrey="http://schemas.android.com/apk/res/com.example.customview"处的包名有问题,此处的包名一定是配置文件中的包名。另一个可能是格式或者编码有问题,格式有问题的时候,即使包名正确也会提示错误,而且找不到具体错误点。此时需要格式化一下,Ctrl+shift+F就是格式化的快捷键。我的问题就是这样解决的,记录一下。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读