掃二維碼與項(xiàng)目經(jīng)理溝通
我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問/技術(shù)咨詢/運(yùn)營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流
這里我們直接繼承SurfaceView,實(shí)現(xiàn)SurfaceHolder.Callback接口,處理surfaceCreated、 surfaceChanged以及surfaceDestroyed方法,這里我們并沒有把按鍵控制傳入,最終游戲的控制方面仍然由View內(nèi)部類處理比 較好,有關(guān)SurfaceView的具體我們可以參見Android開源項(xiàng)目的Camera中有關(guān)畫面捕捉以及VideoView的控件實(shí)現(xiàn)大家可以清晰 了解最終的用意。

- public class cwjView extends SurfaceView implements SurfaceHolder.Callback {
- public cwjView(Context context, AttributeSet attrs) {
- super(context, attrs);
- SurfaceHolder holder=getHolder();
- holder.addCallback(this);
- setFocusable(true);
- }
- public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
- }
- public void surfaceCreated(SurfaceHolder holder) {
- }
- public void surfaceDestroyed(SurfaceHolder holder) {
- }
- @Override
- public void onWindowFocusChanged(boolean hasWindowFocus) {
- }
- }

我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問/技術(shù)咨詢/運(yùn)營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流