内部类中的画布,android
是否可以在活动类中创建一个扩展 SurfaceView 的类作为内部类?类似这样的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.android.iiProject.Presentation.DrawCanvas
android:id="@+id/SurfaceView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
其中 Presentation
是活动类,DrawCanvas
是扩展 SurfaceView
的类,以及 DrawCanvas< /code> 对象是从
Presentation
活动中调用的。
我想要这种方式,因为我想访问 Presentation
活动中可用的方法和变量,并且我不想将它们声明为静态以从其他类访问它们,因为给我带来了很多额外的问题......! 这样它就会在 XML 文件中给我 classNotFoundException
提前非常感谢
Is it possible to have a class extending SurfaceView
within the activity class as an inner class? Something like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.android.iiProject.Presentation.DrawCanvas
android:id="@+id/SurfaceView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Where the Presentation
is the activity class, and the DrawCanvas
is the class extending the SurfaceView
, and a DrawCanvas
object is called from within the Presentation
activity.
I want it this way because I want to have access to methods and variables available from within the Presentation
activity, and I don't want to declare them as static to reach them from the other class, since that causes me a lot of additional problems...!
This way it's giving me classNotFoundException
at the XML file
Thanks a lot in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

是的,这是可能的,您只需以与 XML 不同的方式寻址您的内部类,如下
所示:
请参阅修改现有视图类型,点4.
Yes, that's possible, you just have to adress you inner class in a different way from XML, like this:
Quote:
See modifying an existing view type, point 4.