[英]Android NullPointerException when setting Dialogs background drawable
[英]ANDROID: Phone is slow when setting button backgrounds as an image from drawable
基本上是标题。
我做了一个小游戏,每次玩家移动时,我都希望从新数据中重置和创建棋盘。 这是我试图开始工作的代码。
mustache = new BitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), R.drawable.moustache));
greenHairedPotato = new BitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), R.drawable.greenhairedpotato));
purpleHairedPotato = new BitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), R.drawable.purplehairedpotato));
redHairedPotato = new BitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), R.drawable.redhairedpotato));
yellowHairedPotato = new BitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), R.drawable.yellowhairedpotato));
angryWall = new BitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), R.drawable.angrywall));
blueSpace = new BitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), R.drawable.bluespace));
这是我用于所有drawable的代码。 将其调用到按钮的代码就是这样清除板子:
public void clearBoard(int lX, int lY) {
Button temp;
for(int i = 0; i < buttons.length; i ++){
for(int j = 0; j < buttons.length; j++){
temp = (Button)findViewById(buttons[i][j]);
temp.setBackground(blueSpace);
}
}
}
从这里,我可以设置用户导向的按钮,或更改其他按钮。 但是,清除图像和显示用户所需的时间通常超过一秒钟。
你能帮忙的话,我会很高兴。
谢谢!
两个建议
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.