在创建自定义视图错误 [英] Error in creation of custom view

查看:196
本文介绍了在创建自定义视图错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有customview,我想补充一点,在XML文件中我想这样的,但我得到这个错误

 自定义视图TouchImageView未使用2或3个参数的查看构造;
  XML属性将无法正常工作
 

这是我使用的XML。

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:方向=垂直>

 <查看
   类=com.zoom.TouchImageView
   机器人:ID =@ + ID / webView1
   机器人:layout_width =FILL_PARENT
   机器人:layout_height =FILL_PARENT/>

< / LinearLayout中>
 

解决方案

添加的构造器:

 公共TouchImageView(上下文的背景下,AttributeSet中的AttributeSet)
{
    超(背景下,AttributeSet中的);

    //去做:
}
 

您的自定义视图类。

i have customview, i want to add that in the xml file i tried like this but i am getting this error

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

this is the xml i am using..

 <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>

解决方案

Add the constructor:

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

    //TODO:
}

to your custom View class.

这篇关于在创建自定义视图错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆