2013-01-24 27 views
1

我在庫customAndroidLibrary中聲明瞭CustomLayout類。這CustomLayout延伸ViewGroup。現在我想在我的項目中使用我的layout.xml中的CustomLayout。我已經將這個庫包含在我的項目中。從項目庫中使用customview

CustomLayout類

package com.android.custom; 
public class CustomLayout extends ViewGroup { 
    ..... 
} 

layout.xml

<com.android.custom.CustomLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/animation_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
</com.android.custom.CustomLayout> 

MainActivity

package com.android.ui;  
public class MainActivity extends Activity{ 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.layout); 
    } 
} 

但它扔ClassNotFoundException
即使它沒有檢測到我的Activity也如果我使用的自定義視圖layout.xml 如果我在layout.xml中使用簡單的TextView。然後它沒有給出任何錯誤。

+0

只是爲了驗證,你是否已將庫添加到項目的類路徑中? – Supreethks

回答

0

解決它我自己。

<com.android.custom.CustomLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    class="com.android.custom.CustomLayout" 
    android:id="@+id/animation_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
</com.android.custom.CustomLayout>