内部类中的画布,android

发布于 12-18 06:34 字数 834 浏览 3 评论 0原文

是否可以在活动类中创建一个扩展 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

洋洋洒洒2024-12-25 06:34:44

是的,这是可能的,您只需以与 XML 不同的方式寻址您的内部类,如下

<view
  class="com.yourpackage.YourOuterClass$YourInnerClass" 
  ...
  />

所示:

自定义组件被创建为 XML 中的通用视图,并且
类是使用完整包指定的。 另请注意,内部
我们定义的类是使用 NoteEditor$MyEditText 引用的
表示法是 Java 中引用内部类的标准方法
编程语言。
如果您的自定义视图组件未定义为
一个内部类,那么你也可以声明 View
带有 XML 元素名称的组件,并排除 class 属性。

请参阅修改现有视图类型,点4.

Yes, that's possible, you just have to adress you inner class in a different way from XML, like this:

<view
  class="com.yourpackage.YourOuterClass$YourInnerClass" 
  ...
  />

Quote:

The custom component is created as a generic view in the XML, and the
class is specified using the full package. Note also that the inner
class we defined is referenced using the NoteEditor$MyEditText
notation which is a standard way to refer to inner classes in the Java
programming language.
If your custom View component is not defined as
an inner class, then you can, alternatively, declare the View
component with the XML element name, and exclude the class attribute.

See modifying an existing view type, point 4.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文