【问题标题】:how to initialize a custom surfaceView given that its a nested class in an activity?鉴于它是活动中的嵌套类,如何初始化自定义surfaceView?
【发布时间】:2012-07-20 13:12:48
【问题描述】:

我有一个如下所示的自定义 SurfaceView:

public class GFXSurface extends Activity implements OnTouchListener 
{
    .
    .
    GameSurface gameSurfaceView;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.game); 
        gameSurfaceView = (GameSurface)findViewById(R.id.svgame);
        fullscreen();
        initialize();
    }
    .
    .
    .
    public class GameSurface extends SurfaceView implements Runnable 
    {
        .
        .
        public GameSurface(Context context) 
        {
            super(context);
            ourHolder = getHolder();
        }
        .
        .
        .
    }
}

我的问题是如何在我的 xml 布局中引用它?

我正在使用 xml 布局,因为我需要添加一些 表面视图之上的东西

我尝试了几种方法,但都失败了......

这不起作用:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" >

  <com.bla.bla.GFXSurface.GameSurface
    android:id="@+id/svgame"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
 .
 .
 .
</FrameLayout>

非常感谢您的帮助!!!!

【问题讨论】:

    标签: android surfaceview android-view nested-class xml-layout


    【解决方案1】:

    您的GameSurface 类必须是静态的。您不能在布局中使用非静态嵌套类,因为您需要外部类实例来创建此类的对象。

    【讨论】:

      猜你喜欢
      • 2020-12-13
      • 1970-01-01
      • 2015-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多