eclipse-Android 怎么将主程序添加到欢迎界面里面

问题描述

Android 怎么将主程序添加到欢迎界面里面
我做好了一个欢迎界面,并且做了下按钮触发,里面什么都还没有,我这边有一个游戏主程序,应该怎么样才能合理的添加进去呢? 添加的结果就是 点击这个按钮 就进入这个主程序。下面是代码
这个是我的欢迎界面的代码
package sen.tan;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class dazhuankuaiActivity extends Activity {
BallView myview;
public static int screenWidth ;
public static int screenHeight;
private TextView textview;
Button kaishijieshuguanyu;
ImageView image;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String string = ""欢迎进入疯狂打砖块游戏"";
image = (ImageView) this.findViewById(R.id.image);
image.setImageResource(R.drawable.img1);
textview =(TextView) this.findViewById(R.id.textview);
textview.setTextSize(20);
textview.setTextColor(Color.GREEN);
textview.setBackgroundColor(Color.RED);
textview.setText(string);
kaishi=(Button)findViewById(R.id.button1);
guanyu=(Button)findViewById(R.id.button2);
jieshu=(Button)findViewById(R.id.button3);
kaishi.setWidth(250);
guanyu.setWidth(200);
jieshu.setWidth(150);
kaishi.setTextSize(35);
guanyu.setTextSize(29);
jieshu.setTextSize(24);

    jieshu.setOnClickListener(new Button.OnClickListener(){        public void onClick(View v)        {            dazhuankuaiActivity.this.finish();        }    });    guanyu.setOnClickListener(new Button.OnClickListener(){        public void onClick(View v){            textview.setText(""本游戏由xxx制作,此游戏控制左右按键,来回移动挡板,不让小球掉落,当小球把上方砖块全部打完时,游戏胜利"");        }    });    kaishi.setOnClickListener(new Button.OnClickListener(){         public void onClick(View v)         {         }    });

下面是我找到的主程序
package ab.cc;

import android.app.Activity;

import android.os.Bundle;

import android.util.DisplayMetrics;

import android.view.KeyEvent;

import android.view.MotionEvent;

import android.view.Window;
import android.view.WindowManager;

public class BaomingActivity extends Activity
{

BallView myView;

static int screenWidth;

static int screenHeight;

/** Called when the activity is first created. */
@Override

public void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);/* 定义DisplayMetrics对象 */

DisplayMetrics dm = new DisplayMetrics();

/* 取得窗口属性 */

getWindowManager().getDefaultDisplay().getMetrics(dm);

/* 窗口的宽度 */

screenWidth = dm.widthPixels;

    /* 窗口的高度 */

screenHeight = dm.heightPixels;
//

setTitle(""宽""+screenWidth+"" 高""+screenHeight);

    /* 设置为无标题栏 */

requestWindowFeature(Window.FEATURE_NO_TITLE);

/* 设置为全屏模式 */ 

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREENWindowManager.LayoutParams.FLAG_FULLSCREEN);

myView = new BallView(this);

   //设置显示GameSurfaceView视图

setContentView(myView);
}//end of onCreate()

   //触笔事件

public boolean onTouchEvent(MotionEvent event)
{

return true;}   //按键按下事件

public boolean onKeyDown(int keyCode KeyEvent event)
{

switch (keyCode)    {//菜单按键-设为初始菜单

case KeyEvent.KEYCODE_MENU:

myView.resetGame();    //重新开始break;//中间按键case KeyEvent.KEYCODE_DPAD_CENTER:myView.ball_isRun = !myView.ball_isRun;//开始//暂停    break;

//左方向键

case KeyEvent.KEYCODE_DPAD_LEFT:

        if(myView.ball_isRun){    if(myView.board_left<=myView.board_x_move)        {myView.board_left=0;    myView.board_right=myView.board_length;    }else{    myView.board_left-=myView.board_x_move;            myView.board_right-=myView.board_x_move;}

}

             break;

//右方向键

case KeyEvent.KEYCODE_DPAD_RIGHT:
if(myView.ball_isRun){

    if(screenWidth-myView.board_right<=myView.board_x_move )

{
myView.board_left=screenWidth-myView.board_length;

                                myView.board_right=screenWidth;}else{                myView.board_left+=myView.board_x_move;                                    myView.board_right+=myView.board_x_move;        }        }        break;        //上方向键case KeyEvent.KEYCODE_DPAD_UP:    if(myView.ball_isRun){    if( myView.board_alterable_top==myView.board_default_top)

{

    myView.board_alterable_top-=myView.boardYadd;            myView.board_alterable_bottom-=myView.boardYadd;            }        }        break;      //下方向键   case KeyEvent.KEYCODE_DPAD_DOWN:if(myView.ball_isRun){if( myView.board_alterable_top==myView.board_default_top-myView.boardYadd ){                myView.board_alterable_top=myView.board_default_top;myView.board_alterable_bottom=myView.board_alterable_top+myView.board_thickness;            }        }break;  

//返回键
case KeyEvent.KEYCODE_BACK:

this.finish();break;  

}//end switch
return false;
}

//按键弹起事件

public boolean onKeyUp(int keyCode KeyEvent event)
{

    return true;}

public boolean onKeyMultiple(int keyCode int repeatCount KeyEvent event)
{

return true;}

}

package ab.cc;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RadialGradient;
import android.graphics.Shader;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class BallView extends SurfaceView implements
SurfaceHolder.Callback Runnable {

//线程延时控制 final int ball_sleep=1;//毫秒,延时越大,球速越慢final int ball_r= 8;//小球半径final float ball2_r= 8;//底下滚珠小球半径final int ballXorYadd = 4;//小球的基本位移。测试可行值:2,4//获取屏幕宽度和高度int screen_width;//320;int screen_height;//480;//砖的属性int brick_width;//每块砖宽int brick_height;//每块砖高boolean brick_exist[];//砖是否存在int k ;// 列//到for循环里才初始化int j ;// 行int brick_left = brick_width*(k-1);//到判断语句才初始化int brick_right = brick_width*k;int brick_top = brick_height*j;int brick_bottom = brick_height*(j+1);//挡板的属性int board_length;//挡板长度:80比较合适,可以随意修改但别超过screen_widthfinal int boardYadd = 16;//按上下键时挡板y方向位移量。经验证4、8、16可以,12不行final int board_x_move = 30;//挡板x方向位移量:可以随意自定义int board_left;//挡板左侧(可变)int board_right;//挡板右侧(可变)int board_thickness;//挡板厚度int board_default_top;//即435挡板的top面初始位置int board_alterable_top;//挡板上侧(可变)int board_alterable_bottom;//挡板下侧(可变)int ball_default_x;//球的初始x坐标int ball_default_y;//球的初始y坐标//球的即时坐标(可变):int ball_x;//球心横坐标int ball_y;//球心纵坐标//球的前一步的y坐标int ball_previous_y;int ball_x_speed;//球的横向偏移量//可变int ball_y_speed;//球的纵向偏移量//可变boolean ball_isRun;//球是否在动// 控制循环boolean mbLoop;// 定义SurfaceHolder对象SurfaceHolder mSurfaceHolder = null;//获得分数int score;/* 唤醒渐变渲染 */Shader mRadialGradient = null;

//------------------------------------------------------------------------------------------------------//
public BallView(Context context) {
super(context);
// 实例化SurfaceHolder
mSurfaceHolder = this.getHolder();
// 添加回调
mSurfaceHolder.addCallback(this);
this.setFocusable(true);

    //获取屏幕宽度和高度    screen_width = BaomingActivity.screenWidth;//320    screen_height = BaomingActivity.screenHeight;//480    //砖的属性    brick_width = screen_width/5;//每块砖宽64    brick_height = screen_height/15;//每块砖高32    //挡板的属性    board_length = screen_width/4;//挡板长度:80比较合适,可以随意修改但别超过screen_width    board_left = (screen_width-board_length)/2;//挡板左侧(可变)    board_right = (screen_width+board_length)/2;//挡板右侧(可变)    board_thickness = 5;//挡板厚度    board_default_top = 13*screen_height/15;//即435挡板的top面初始位置    board_alterable_top = board_default_top;//挡板上侧(可变)    board_alterable_bottom = board_alterable_top+board_thickness;//挡板下侧(可变)    ball_default_x = screen_width/2;//球的初始x坐标    ball_default_y = board_default_top - ball_r;//球的初始y坐标    //球的即时坐标(可变):    ball_x = ball_default_x;    ball_y = ball_default_y;    //球的前一步的y坐标    ball_previous_y = 0;    ball_x_speed = ballXorYadd;//球的横向偏移量    ball_y_speed = ballXorYadd;//球的纵向偏移量    mbLoop = true;    ball_isRun = false;    score=0;    brick_exist = new boolean[25];    for (int i = 0; i < 25; i++) {        brick_exist[i] = true;    }    /* 构建RadialGradient对象,设置半径的属性 */    mRadialGradient = new RadialGradient(ball_x ball_y ball_r//球中心坐标xy半径r            new int[]{Color.WHITEColor.BLUEColor.GREENColor.REDColor.YELLOW}//颜色数组            null//颜色数组中每一种颜色对应的相对位置,为空的话就是平均分布,由中心向外排布            Shader.TileMode.REPEAT);//渲染模式:重复}public void resetGame(){    ball_isRun = false;    score =0;//分数    ball_x_speed = ballXorYadd;//球的横向偏移量    ball_y_speed = ballXorYadd;//球的纵向偏移量    ball_x = screen_width/2;//球心起始横坐标    ball_y = board_default_top - ball_r;//球心起始纵坐标    board_left = (screen_width-board_length)/2;//挡板左侧    board_right = (screen_width+board_length)/2;//挡板右侧    board_alterable_top = board_default_top;//挡板上侧    board_alterable_bottom = board_alterable_top+board_thickness;//挡板下侧    for (int i = 0; i < 25; i++) {        brick_exist[i] = true;    }}//---------------------------------绘图循环开始----------------------------------public void run() {    while (mbLoop&&!Thread.currentThread().isInterrupted()) {        try {            Thread.sleep(ball_sleep);        }        catch (InterruptedException e) {            Thread.currentThread().interrupt();        }        //球的前一步y坐标        ball_previous_y = ball_y;        if (ball_isRun) {            ballRunning();// 让小球移动            boardPositionCheck();//检测挡板是否处于“中线”位置,是就随小球上升一步,直至到“上线”            hitWallCheck();//墙壁碰撞检测            hitBoardCheck();//挡板碰撞检测            hitBrickCheck();//砖块碰撞检测        }        synchronized (mSurfaceHolder)         {            Draw();        }    }}//---------------------------------绘图循环结束----------------------------------//------------------------------------------------------------------------------//让小球移动public void ballRunning() {    ball_x += ball_x_speed;    ball_y -= ball_y_speed;}//朝左或朝右碰撞后小球水平方向逆向public void ballLeftOrRightHit() {    ball_x_speed *= -1;}//朝上或朝下碰撞后小球竖直方向逆向public void ballUpOrDownHit() {    ball_y_speed *= -1;}public void ballcornerHit() {    ball_x_speed *= -1;    ball_y_speed *= -1;}public void ballStraightUp() {//功能没实现,这是多余代码    ball_x_speed = 0;//注意在其他地方恢复    ball_y_speed *= -1;}//-------------------墙壁碰撞检测开始-------------------------------------public void hitWallCheck() {    // 左碰墙    if (ball_x <= ball_r &&         ball_y >= ball_r && ball_y <= screen_height)     {        ballLeftOrRightHit();    // 右碰墙    }    if (ball_x >= screen_width - ball_r && //不能写为 else if因为可能恰好碰到角落。               ball_y >= ball_r && ball_y <= screen_height)     {        ballLeftOrRightHit();    }    // 上碰墙    if (ball_x >= ball_r && ball_x <= screen_width - ball_r &&              ball_y <= ball_r + brick_height) //、、、、、、、、、、、、、、、25号修改    {        ballUpOrDownHit();    }    // 下碰墙    if (ball_x >= ball_r && ball_x <= screen_width - ball_r &&              ball_y >= screen_height-ball_r)     {        ballUpOrDownHit();        if(score<=10){            score = 0;        }        else score-=10;    }}//-------------------墙壁碰撞检测结束-------------------------------------//-----------------------------挡板碰撞检测开始---------------------------public void hitBoardCheck() {    // 下碰挡板正面    if (ball_x >= ball_r && ball_x <= screen_width - ball_r && //在屏幕内,起码条件        ball_x >= board_left && ball_x <= board_right && //在挡板X域上方        ball_y == board_alterable_top - ball_r &&//球面与挡板相切        ball_previous_y <= board_alterable_top - ball_r  //确定球是从上方下落        )    {        if(board_alterable_top==board_default_top-boardYadd ){//如果弹簧伸张,挡板位于上线            ballHitBoardlower();//作用:ball_y_move减小;挡板被打下;小球Y向运动反向        }        else if(board_alterable_top==board_default_top){//如果弹簧压缩,挡板位于下线            boardHitBallHigher();//作用:ball_y_move增加;挡板弹上;小球Y向运动反向        }    }    //斜碰挡板右上角//经验证有效    else if(Math.pow(board_right-ball_x 2)+Math.pow(board_alterable_top-ball_y2)<=Math.pow(ball_r 2)&&            ball_x>board_right && ball_y<board_alterable_top)    {        ballcornerHit();    }    //斜碰挡板的左上角//经验证有效    else if(Math.pow(board_left-ball_x 2)+Math.pow(board_alterable_top-ball_y2)<=Math.pow(ball_r 2)&&            ball_x<board_left && ball_y<board_alterable_top)    {        ballcornerHit();    }}//-----------------------------挡板碰撞检测结束--------------------------private void boardHitBallHigher() {//增强    ballUpOrDownHit();//小球Y方向反向ball_y_speed变为正数    if(ball_y_speed == ballXorYadd ){        ball_y_speed += ballXorYadd;//离开挡板后小球Y方向速度增强    }    if( boardYadd > ball_y_speed ){//在线程这一轮,小球上升多少,挡板就上升多少。        board_alterable_top = board_default_top - ball_y_speed;        board_alterable_bottom= board_alterable_top+board_thickness;//挡板下层面    }}//检测挡板是否处于“中线”位置,是就随小球上升一步,直至到“上线”private void boardPositionCheck() {//还可直接利用球的位置刷新,board_top与球心相差ball_r    if(board_alterable_top < board_default_top && board_alterable_top > board_default_top-boardYadd){        //挡板随球上升        if(board_alterable_top - ball_y_speed >= board_default_top-boardYadd){            board_alterable_top -= ball_y_speed;//挡板上层面            board_alterable_bottom= board_alterable_top+board_thickness;//挡板下层面        }        else{            board_alterable_top = board_default_top-boardYadd;//挡板上层面            board_alterable_bottom= board_alterable_top+board_thickness;//挡板下层面        }    }}private void ballHitBoardlower() {//减弱    board_alterable_top=board_default_top;    board_alterable_bottom=board_default_top+board_thickness;//挡板被打退    ballUpOrDownHit();//小球Y方向反向    if(ball_y_speed==2*ballXorYadd){        ball_y_speed -= ballXorYadd;//小球Y方向速度减弱    }}//砖块碰撞检测开始-----------------------------------------------------------public void hitBrickCheck() {    for (int i = 0; i <25 ; i++) {    if (brick_exist[i]) {        k = i % 5+1;// 12345循环        j = i / 5+1;// 11111;22222;...;55555        brick_left = brick_width*(k-1);        brick_right = brick_width*k;        brick_top = brick_height*j;        brick_bottom = brick_height*(j+1);        //朝下碰砖的top面 AAAAAAAAAAAAAAAAAAAAA        if(ball_x >= brick_left && ball_x <= brick_right &&           ball_y >= brick_top-ball_r && ball_y < brick_top)         {            ballUpOrDownHit();            brick_exist[i] = false;            score+=4;            //朝下正碰2砖中间,i砖右上角检测            if(k!=5 && ball_x == brick_right)//如果不是第5列砖的右侧边            {                //如果砖[i+1]存在                if(brick_exist[i+1]){                    brick_exist[i+1] = false;                    score+=4;                }            }            //朝下正碰2砖中间,i砖左上角检测            else if(k!=1 && ball_x == brick_left)//如果不是第1列砖的左侧边            {                //如果砖[i-1]存在                if(brick_exist[i-1]){                    brick_exist[i-1] = false;                    score+=4;                }            }        }        //朝上碰砖的bottom面 BBBBBBBBBBBBBBBBB        else if(ball_x >= brick_left && ball_x <= brick_right &&                ball_y > brick_bottom&& ball_y <= brick_bottom + ball_r )        {            ballUpOrDownHit();            brick_exist[i] = false;            score+=4;            //朝上正碰2块砖中间--i砖的右下角检测            if(k!=5 && ball_x == brick_right) //如果不是第5列砖的右侧边            {                if(brick_exist[i+1]){//如果砖[i+1]存在                    brick_exist[i+1] = false;                    score+=4;                }            }            //朝上正碰2块砖中间--i砖的左下角检测            else if(k!=1 && ball_x == brick_left) //如果不是第1列砖的左侧边            {                if(brick_exist[i-1]){//如果砖[i-1]存在                    brick_exist[i-1] = false;                    score+=4;                }            }        }        //朝右碰砖的left面CCCCCCCCCCCCCCCCC        else if(ball_x >= brick_left -ball_r&&ball_x < brick_left&&           ball_y >= brick_top && ball_y <= brick_bottom)        {            ballLeftOrRightHit();            brick_exist[i] = false;            score+=4;            //朝右正碰2块砖中间,左下角检测            if(j!=5 && ball_y == brick_bottom)//如果不是第5行砖的下侧边            {                if(brick_exist[i+5]){//如果砖[i+5]存在                    brick_exist[i+5] = false;                    score+=4;                }            }            //朝右正碰2块砖中间,左上角检测            else if(j!=1 && ball_y == brick_top)//如果不是第1行砖的上侧边            {                if(brick_exist[i-5]){//如果砖[i-5]存在                    brick_exist[i-5] = false;                    score+=4;                }            }        }        //朝左碰砖的right面DDDDDDDDDDDDDDDDDD        else if(ball_x >= brick_right && ball_x <= brick_right+ball_r&&           ball_y >= brick_top && ball_y <= brick_bottom)        {            ballLeftOrRightHit();            brick_exist[i] = false;            score+=4;            //朝左正碰2块砖中间,右下角检测            if(j!=5 && ball_y == brick_bottom )//如果不是第5行砖的下侧边            {                if(brick_exist[i+5]){//如果砖[i+5]存在                    brick_exist[i+5] = false;                    score+=4;                }            }             //朝左正碰2块砖中间,右上角检测            else if(j!=1 && ball_y == brick_top )//如果不是第1行砖上侧边            {                if(brick_exist[i-5]){//如果砖[i-5]存在                    brick_exist[i-5] = false;                    score+=4;                }            }        }        /////////////////////////////////////////        //斜碰i砖的左下角EEEEEEEEEEEEEEEEEEEEEEEE        else if(( i-1<0||(i-1>=0&&!brick_exist[i-1]) ) &&                (i+5>=25||(i+5<25&&!brick_exist[i+5]) )&&                Math.pow(brick_left-ball_x 2)+Math.pow(brick_bottom-ball_y2)<=Math.pow(ball_r 2)&&                ball_x>brick_left-ball_r && ball_x<brick_left &&                 ball_y>brick_bottom && ball_y<brick_bottom+ball_r )        {            ballcornerHit();            brick_exist[i] = false;            score+=4;        }        //斜碰i砖的右下角FFFFFFFFFFFFFFFFFFFFFFFFFF        else if( (i+1>=25||(i+1<25&&!brick_exist[i+1]) )&&                 (i+5>=25||(i+5<25&&!brick_exist[i+5]) )&&                Math.pow(brick_right-ball_x 2)+Math.pow(brick_bottom-ball_y2)<=Math.pow(ball_r 2)&&                ball_x>brick_right&&ball_x<brick_right+ball_r&&                ball_y>brick_bottom&&ball_y<brick_bottom+ball_r )        {            Log.v(""----------""right bottom hit""+i+"":""+brick_exist[i]);            ballcornerHit();             brick_exist[i] = false;            score+=4;        }        //斜碰i砖的右上角GGGGGGGGGGGGGGGGGGGGGGGG        else if( (i+1>=25||(i+1<25&&!brick_exist[i+1]) )&&                (i-5<0||(i-5>0&&!brick_exist[i-5]) )&&                Math.pow(brick_right-ball_x 2)+Math.pow(brick_top-ball_y2)<=Math.pow(ball_r 2)&&                ball_x>brick_right && ball_x<brick_right+ball_r&&                ball_y>brick_top-ball_r && ball_y<brick_top)                  {            ballcornerHit();            brick_exist[i] = false;            score+=4;        }        //斜碰i砖的左上角HHHHHHHHHHHHHHHHHHHHHHHHHH        else if((i-1<0||(i-1>=0&&!brick_exist[i-1])) &&                (i-5<0||(i-5>=0&&!brick_exist[i-5])) &&                Math.pow(brick_left-ball_x 2)+Math.pow(brick_top-ball_y2)<=Math.pow(ball_r 2)&&                ball_x>brick_left-ball_x && ball_x<brick_left &&                ball_y>brick_top-ball_r && ball_y<brick_top )        {            ballcornerHit();            brick_exist[i] = false;            score+=4;        }    }//end if    }//end for  }//end hitBrickCheck()//砖块碰撞检测结束-----------------------------------------------------------//------------------------------------------public boolean gameOver(){    int count = 0;    for(boolean s:brick_exist){        if(!s){            count++;        }    }    if(count == 25){        return true;    }else{        return false;    }}//------------------------------------------//---------------绘图方法开始------------------------public void Draw() {    // 锁定画布,得到canvas    Canvas canvas = mSurfaceHolder.lockCanvas();    if (mSurfaceHolder == null || canvas == null) {        return;    }    // 绘图    Paint mPaint = new Paint();    // 设置取消锯齿效果    mPaint.setAntiAlias(true);    mPaint.setColor(Color.GREEN);    // 绘制矩形--背景    canvas.drawRect(0 0 screen_width brick_height-2 mPaint);    mPaint.setColor(Color.MAGENTA);    // 绘制矩形--背景    canvas.drawRect(0 brick_height-2 screen_width screen_height mPaint);    mPaint.setColor(Color.RED);//设置字体颜色    mPaint.setTextSize(brick_height-7);//设置字体大小    canvas.drawText(""得分:""+score 0 brick_height-7 mPaint);    // 绘制顶层挡板````````````````````````````````````````````````````````25号修改    mPaint.setColor(Color.BLACK);//设置颜色     mPaint.setStrokeWidth(4);//设置粗细    canvas.drawLine(0 brick_height-2 screen_width brick_height-2 mPaint);    for (int i = 0; i <25 ; i++) {        if (brick_exist[i]) {            k = i % 5+1;// 12345循环            j = i / 5+1;// 11111;22222;...;55555            brick_left = brick_width*(k-1);            brick_right = brick_width*k;            brick_top = brick_height*j;            brick_bottom = brick_height*(j+1);            mPaint.setStyle(Paint.Style.FILL);// 设置实心画笔            mPaint.setColor(Color.BLACK);            canvas.drawRect(brick_left+1 brick_top+1 brick_right-1brick_bottom-1 mPaint);            mPaint.setStyle(Paint.Style.STROKE);// 设置空心画笔            mPaint.setStrokeWidth(2);//设置粗细            mPaint.setColor(Color.RED);            canvas.drawRect(brick_left+3 brick_top+3 brick_right-3brick_bottom-3 mPaint);        }    }    // 设置实心画笔    mPaint.setStyle(Paint.Style.FILL);    {        mPaint.setShader(mRadialGradient);        canvas.drawCircle(ball_x ball_y ball_r mPaint);    }       Paint mPaint2 = new Paint();        // 设置取消锯齿效果    mPaint2.setAntiAlias(true);     // 设置实心画笔    mPaint2.setStyle(Paint.Style.FILL);    {       mPaint2.setColor(Color.BLACK);    /* 绘制矩形挡板 */    canvas.drawRect(board_left board_alterable_top board_right board_alterable_bottommPaint2);    float board2_bottom = screen_height - 2*ball2_r;//164    float board2_top = board2_bottom - 4;//160    //线段端点坐标数组    float x0 = board_left+(board_right-board_left)/4;    float y0 = board_alterable_bottom;//440或者444    float springAdd = (board2_top- board_alterable_bottom)/8;//即2.5或者2:弹簧小线段的y向长度    float springWidth = 5.0f;//弹簧小线段的x向长度    float x1 = x0 - springWidth;    float y1 = y0 + springAdd;    float x2 = x0 + springWidth;    float y2 = y0 + 3*springAdd;    float x3 = x1 ;    float y3 = y0 + 5*springAdd;    float x4 = x2;    float y4 = y0 + 7*springAdd;    float x5 = x0 ;    float y5 = board2_top;//即460     float between_spring = (board_right-board_left)/2;    float pts[] = { x0y0x1y1                    x1y1x2y2                    x2y2x3y3                    x3y3x4y4                    x4y4x5y5};    float pts2[] = {x0+between_springy0 x1+between_springy1                    x1+between_springy1 x2+between_springy2                    x2+between_springy2 x3+between_springy3                    x3+between_springy3 x4+between_springy4                    x4+between_springy4 x5+between_springy5};    mPaint2.setStrokeWidth(2);//设置弹簧粗细    //绘制2个弹簧    canvas.drawLines(pts mPaint2);    canvas.drawLines(pts2 mPaint2);    //绘制下层挡板    canvas.drawRect(board_left board2_top board_right board2_bottommPaint2);    mPaint2.setColor(Color.BLACK);//    // 绘制最下面的两个“轮子”(圆心x圆心y半径rp)     canvas.drawCircle(board_left+ball2_r screen_height-ball2_r ball2_r mPaint2);//圆    canvas.drawCircle(board_right-ball2_r screen_height-ball2_r ball2_r mPaint2);    mPaint2.setColor(Color.WHITE);//    }//实心画笔mPaint2结束    if(gameOver()){ 

// mbLoop = false;//注释掉的话GAME OVER后也可重启
ball_isRun = false;
mPaint2.setColor(Color.BLACK);//设置字体颜色
mPaint2.setTextSize(40.0f);//设置字体大小
canvas.drawText(""GAME OVER"" screen_width/32+40 screen_height/16*9-70 mPaint2);
mPaint2.setTextSize(20.0f);//设置字体大小
canvas.drawText(""Press ""MENU"" button to restart
screen_width/32 //320/32=10
screen_height/16*9 //480/16=3030*9=270
mPaint2);
canvas.drawText(""Press ""BACK"" button to exit.""
screen_width/32 //320/32=10
screen_height/16*10 //480/16=3030*10=300
mPaint2);
}
// 绘制后解锁,绘制后必须解锁才能显示
mSurfaceHolder.unlockCanvasAndPost(canvas);
}// end of Draw()
//---------------------绘图方法结束-----------------------------------------------

// 在surface的大小发生改变时激发public void surfaceChanged(SurfaceHolder holder int format int width        int height) {}// 在surface创建时激发public void surfaceCreated(SurfaceHolder holder) {    new Thread(this).start();// 开启绘图线程}// 在surface销毁时激发public void surfaceDestroyed(SurfaceHolder holder) {    // 停止循环    mbLoop = false;}

}
能否回答的详细一点,学的时间短,求帮忙

解决方案

放到你结束按钮的点击事件里:

Intent intent=new Intent(thisBaomingActivity.class);startActivity(intent);

解决方案二:

Intent intent=new Intent(thisBaomingActivity.class);
startActivity(intent);
放到开始里。

时间: 2024-10-25 16:19:54

eclipse-Android 怎么将主程序添加到欢迎界面里面的相关文章

Android Studio(十):添加assets目录

Android Studio相关博客: Android Studio(一):介绍.安装.配置 Android Studio(二):快捷键设置.插件安装 Android Studio(三):设置Android Studio编码 Android Studio(四):Android Studio集成Genymotion Android Studio(五):修改Android Studio项目包名 Android Studio(六):Android Studio添加注释模板 Android Studio

android开发环境搭建详解(eclipse + android sdk)_Android

本开发环境为:eclipse + android sdk,步骤说明的顺序,没有特别要求,看个人爱好了 步骤说明: 1.安装eclipse 2.配置jdk 3.安装android sdk 4.安装ADT,关联eclipse和android 详细说明: 1.安装eclipse * 到官方网下载eclipse(http://www.eclipse.org/downloads/),我是下载的Eclipse IDE for Java EE Developers. * 正常解压安装,注意记得路径就可以了 2

android 中notifyDataSetChanged() 无法添加item!!

问题描述 android 中notifyDataSetChanged() 无法添加item!! 我在onActivityResult()方法中调用 myadapter.notifyDataSetChanged()来添加更新的内容,但是只能显示一行,再按"添加"按钮不能添加. 问一下是什么原因? 解决方案 onActivityResult是从另一个activity返回的时候调用的.看你这代码,每次返回当前activity,list都是重新new的,再次添加跟第一次添加没区别.不会显示多个

如何在 android 中动态的添加 checkboxs?

问题描述 如何在 android 中动态的添加 checkboxs? 我想在android中动态的创建edittext 字段,也创建了按钮点击事件.当我点击按钮,check boxes就会显示.但是当我在onclick动作上创建checkbox对象,就显示错误.使用的代码如下,为什么会显示错误呢? public class InflationActivity extends Activity {@Overridepublic void onCreate(Bundle savedInstanceS

eclipse android程序没有提示错误,但程序调试时终止运行

问题描述 eclipse android程序没有提示错误,但程序调试时终止运行 刚在学习android开发,好多不懂,我按照书上的代码一个个敲的,以前敲过一遍在原先的eclipse能运行,最近换了个系统用了4.5的eclipse,环境变量应该也没问题,又照着书上敲了一边,我用手机,运行后就显示"已停止运行",程序没提示错误,不知道怎么回事,我连着照着书上敲了两个项目都是这样,求救...... 下面这是在模拟器上给出的错误提示 解决方案 这不提示很明显,LoginActivity的布局中

android开发中listview添加图片

问题描述 android开发中listview添加图片 map1.put("image",R.drawable.jiantou); 我在listview中添加图像时,引用图像的地址,如上所示,但提示错误The method put(String, String) in the type HashMap is not applicable for the arguments (String, int) 但我看别人的代码都可以直接引用图像地址的,请大神帮忙解决一下,谢啦!! 解决方案 Ma

关于Android锁定文件,添加密码锁的实现,请教各路大神

问题描述 关于Android锁定文件,添加密码锁的实现,请教各路大神 想实现Android的文件锁定或者文件夹的锁定,给文件添加一个密码锁,答对密码才能打开文件,请教各路大神怎么实现的呢? 解决方案 http://download.csdn.net/detail/ziyinghui123/6377129 解决方案二: 开启一个服务在后台跑 Taskinfo中获取到当前TopActivity的包名 和你记录到的包名进行比对 相同就弹出密码界面

布局-android 将自定义组件添加到xml后,程序崩溃

问题描述 android 将自定义组件添加到xml后,程序崩溃 activity_main中的代码是这样的 xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:id

android 调用系统的添加联系人界面,如何获得添加的联系人的名字或者电话号码?

问题描述 android 调用系统的添加联系人界面,如何获得添加的联系人的名字或者电话号码? 如题,请问我怎么样才能获得返回结果呢?意思就是我要添加联系人,并在保存的时候知道这个联系人的号码和姓名? 我调用startActivityForResult data直接返回null,resultCode 都不对,返回0,请问我该怎么写才能获得返回的结果? 解决方案 http://blog.csdn.net/snwrking/article/details/7601794 解决方案二: 跳转之前,在in