安卓onDraw重绘和invalidate()的问题,新手,各位帮个忙。

wang3607476 2015-02-04 09:59:19
大家帮我看看 我做的 不知道那里不对。。我invalidate() 重绘 他不执行ondraw 有什么地方不对么? 还是怎么回事。。 谢谢

ondraw方法什么也没有 就一个吐死框调试的。。 具体的还没写了。。 不执行onDraw()。。


怎么处理啊。。有什么方法呢? 谢谢了

分数不多了 各位凑合下把 谢了




public class GameActivity extends Activity {
private Context gameContext;
private int screenHeight;
private int screenWidth;
private Button Buttonreturn;
private Button Buttonsave;
private Button ButtonSeeting;
private TableLayout Tabshowinfo;
private TableLayout Tablogo;
private ImageView Border_left;
private float boardTableLayoutWidth;
private float boardTableLayoutHeight;
private final int COLS = 15;
private final int ROWS = 15;
private float showinfoTabWidth ;
private float Border_left_ImgWidth ;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
gameContext = this;
Toast.makeText(getApplicationContext(), "跳转到棋盘", Toast.LENGTH_SHORT).show();
GobangBoard inner = new GobangBoard(gameContext);
Toast.makeText(getApplicationContext(), "跳转完成 返回", Toast.LENGTH_SHORT).show();
Buttonreturn = (Button) findViewById(R.id.returnButton);
Buttonsave = (Button) findViewById(R.id.saveButton);
ButtonSeeting= (Button) findViewById(R.id.SeetingButton);
Tabshowinfo = (TableLayout) findViewById(R.id.showinfoTab);
Tablogo = (TableLayout) findViewById(R.id.showinfoTab);
Border_left = (ImageView) findViewById(R.id.Border_left);
showinfoTabWidth = Tabshowinfo.getWidth() ;
Border_left_ImgWidth = Border_left.getWidth();
}

/*
* 获取屏幕的大小 screenHeight : 屏幕的高 screenWidth : 屏幕的长
*/
public void getScreen() {
screenHeight = this.getWindowManager().getDefaultDisplay().getHeight();
screenWidth = this.getWindowManager().getDefaultDisplay().getWidth();
}

/*
* get 屏幕的长高 getScreenHeight() : 屏幕的高 getScreenWidth() : 屏幕的长
*/
public int getScreenHeight() {
return screenHeight;
}

public int getScreenWidth() {
return screenWidth;
}
/*
* 组建的长 get
*/
public float getBoardTableLayoutWidth() {
return boardTableLayoutWidth;
}
public float getBorder_left_ImgWidth() {
return Border_left_ImgWidth;
}
public class GobangBoard extends View{
View view ;
public int COLS = 15 ;
public int ROWS = 15 ;
public float screenHeight = getScreenHeight();
public float screenWidth = getScreenWidth();
public float Excess = (float) (screenWidth - screenHeight
- getBorder_left_ImgWidth() - getBoardTableLayoutWidth());
public float ChessSpacing = (float) (screenHeight / (COLS - 1));
public float XCoords = (float) (screenHeight / (COLS - 1)) / 2;
public float YCoords = (float) (Excess/2 + getBorder_left_ImgWidth());
// public float BoardFOLD = 1 ; // 棋盘倍数 暂时不需要
public float[][] BoardXROW = new float[COLS][ROWS];
public float[][] BoardYCOL = new float[COLS][ROWS];
public Context context = null ;
public GobangBoard(Context context) {
super(context);
screenHeight = getScreenHeight();
screenWidth = getScreenWidth();
Excess = (float) (screenWidth - screenHeight
- getBorder_left_ImgWidth() - getBoardTableLayoutWidth());
ChessSpacing = (float) (screenHeight / (COLS - 1));
XCoords = (float) (screenHeight / (COLS - 1)) / 2;
YCoords = (float) (Excess/2 + getBorder_left_ImgWidth());
BoardXY(XCoords ,YCoords);
invalidate();
}

@Override
protected void onDraw(Canvas canvas) {
// TODO 自动生成的方法存根
super.onDraw(canvas);
Toast.makeText(getApplicationContext(), "进入绘图", Toast.LENGTH_SHORT).show();
}
public void BoardXY(float X, float Y) {
// 计算坐标
float XRecord = X; // 记录X坐标
float YRecord = Y; // 记录Y坐标
for (int i = 0; i < COLS; ++i) {
Y = YRecord;
for (int j = 0; j < ROWS; ++ j) {
BoardXROW[i][j] = X;
BoardYCOL[i][j] = Y;
Y += ChessSpacing;
}
X += ChessSpacing;
}
Toast.makeText(getApplicationContext(), "计算坐标完成", Toast.LENGTH_SHORT).show();
}

}
}

...全文
668 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
水的川 2015-02-04
  • 打赏
  • 举报
回复
invalidate()是用在已经绘制好view以后(注意是绘制好view以后不是之前),当改变这个view的时候需要调用这方法。你现在都没绘制就调用了,直接把view给pop掉了,当然不会调用那个ondraw方法了。。
wang3607476 2015-02-04
  • 打赏
  • 举报
回复
顶顶顶。。 各位大神大哥帮帮忙啊。。

80,348

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧