一、在XML中定义View的一个小错误
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<com.fxhy.stady.HelloView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
super.onCreate(savedInstanceState);
二、解决方法
/**
* 这个是我们要在XML中初始化用的
* */
public HelloView(Context context,AttributeSet attrs){
super(context, attrs);
三、另一中在XML中的View布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<view class="com.fxhy.stady.HelloView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
本文介绍在Android开发中如何解决自定义View在XML布局文件中引发的NoSuchMethodException错误,并提供两种XML布局实现方式。
3328

被折叠的 条评论
为什么被折叠?



