自定义视图到xml

时间:2012-03-20 16:36:07

标签: android android-layout android-canvas

我正在制作游戏,我不希望整个画布占据屏幕。有没有办法让我的类将SurfaceView扩展到xml?我想把它放到xml中,这样我就可以在屏幕上调整SurfaceView的位置和大小。

1 个答案:

答案 0 :(得分:1)

在src中

public class MySurView extends SurfaceView {
  public MySurView(Context context) {
    super(context);
  }
  // you must overide this constructor
  public MySurView(Context context, AttributeSet attrs) {
    super(context, attrs);
  }
}
xml中的

<package.name.MySurView
    android:id="@+id/surview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
</package.name.MySurView>
相关问题