Android游戏开发(一):界面全屏以及画笔的使用

@authur : qingdujun  2015年4月15日21:00:03

 

MainActivity.java中设置全屏,注意:其设置必须在setContentView之前;

package com.qdj.gameone;

import com.qdj.ui.ViewOne;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        /* Note that some flags must be set before the window decoration is created. */
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        /* Flag for the "no title" feature, turning off the title at the top of the screen. */
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        
        setContentView(new ViewOne(this));
    }
}
/**
 * 中文(Chinese):
 * getWindow().setFlags() ——用于去除界面最上面的电池显示部分;
 * requestWindowFeature() ——是用于去除标题栏(并不是最上面的电池部分);
 */

自定义View

package com.qdj.ui;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;

public class ViewOne extends View {

    private Paint paint = null;
    
    public ViewOne(Context context) {
        super(context);
        
        paint = new Paint();
        /*setting or clearing the ANTI_ALIAS_FLAG bit 
         * AntiAliasing smooths out the edges of what is being drawn.*/
        paint.setAntiAlias(true);
        /*Controls whether the screen should remain on.*/
        setKeepScreenOn(true);
        paint.setColor(Color.RED);
    }
    
    @Override
    public void onDraw(Canvas canvas) {
        /* set background color. */
        canvas.drawColor(Color.BLACK);
        canvas.drawText("Android Game Develop", 30, 30, paint);
    }
}

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。