Android 在项目中使用库中的customview
我已在库customAndroidLibrary中声明CustomLayout类。此自定义布局扩展了视图组。现在我想在我的项目中的layout.xml中使用这个CustomLayout。我已将此库包含在我的项目中 自定义布局类Android 在项目中使用库中的customview,android,android-custom-view,Android,Android Custom View,我已在库customAndroidLibrary中声明CustomLayout类。此自定义布局扩展了视图组。现在我想在我的项目中的layout.xml中使用这个CustomLayout。我已将此库包含在我的项目中 自定义布局类 package com.android.custom; public class CustomLayout extends ViewGroup { ..... } layout.xml <com.android.custom.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>
但它抛出了ClassNotFoundException。
如果我使用layout.xml中的自定义视图,即使它也不会检测到我的活动
如果我在layout.xml中使用simple TextView。那它就不会出错。我自己解决了
<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>
为了验证,您是否已将库添加到项目的类路径中?
<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>