2012-06-14 108 views
1

我有一个名为CropImageView的类,它从ImageView扩展。但下面的语句使castException如何找到自定义扩展视图的视图

CropImageView image = (CropImageView) findViewById(R.id.image); 

这里是xml文件:

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

    <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="horizontal"> 

     <ImageView android:id="@+id/image" 
       android:background="#55000000" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_x="0dip" 
       android:layout_y="0dip"/> 
    </RelativeLayout> 
    </FrameLayout> 

你有什么建议吗?

回答

1

您应该在XML中使用CropImageView规范名称。例如:

<your.package.CropImageView 
    android:id="@+id/image" 
    android:background="#55000000" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_x="0dip" 
    android:layout_y="0dip"/> 
1

尝试在您的布局中使用<com.your.package.CropImageView />而不是<ImageView />

相关问题