创建自定义视图时出错

时间:2011-12-02 05:46:32

标签: android custom-view

我有自定义视图,我想在xml文件中添加我尝试过这样但我收到此错误

  Custom view TouchImageView is not using the 2- or 3-argument View constructors;
  XML attributes will not work

这是我正在使用的xml ..

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

 <view 
   class="com.zoom.TouchImageView"
   android:id="@+id/webView1"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent" />

</LinearLayout>

1 个答案:

答案 0 :(得分:16)

添加构造函数:

public TouchImageView(Context context, AttributeSet attributeSet)
{
    super(context, attributeSet);

    //TODO:
}

到您的自定义View类。