1. 程式人生 > >Android應用:SurfaceView中新增控制元件

Android應用:SurfaceView中新增控制元件

上次說了 如何使用SurfaceView,文章連結:

但如何在SurfaceView中新增控制元件呢?

1、首先,將SurfaceView的建構函式修改為兩個引數的

public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
}

2、在Activity佈局檔案中新增SurfaceView和控制元件
<com.example..MyView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/view"
        />
<TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/textView"" />