我有一个问题,我在编程方面很好,所以请解释我就像posible一样简单:)
我有这个代码,显示级别菜单(用户点击级别数),但我想在此视图上绘制特定的背景颜色。
有什么办法吗?
//levelmenu stuff________________________________________________________________________________
level_circles_border_dp = dpToPx(level_circles_border);
int circles_in_x = (int) Math.ceil(Math.sqrt(Brick_Pattern.length));
int circles_in_y = (int) Math.ceil((float) Brick_Pattern.length / (float) circles_in_x);
int radius = (int) (((ScreenWidth() - ((float) level_circles_border_dp * (float) (circles_in_x + 1))) / (float) circles_in_x) / 2);
int total_circles_height = (circles_in_y * ((radius * 2) + level_circles_border_dp)) + level_circles_border_dp;
int current_lvl = 1;
for (int y = 0; y < circles_in_y; y++) {
for (int x = 0; x < circles_in_x; x++) {
if (current_lvl <= Brick_Pattern.length)
Level_Buttons[current_lvl - 1] = new level_button("" + current_lvl, (int) (radius / 3.0f), FORTE, getResources().getColor(R.color.black), level_circles_border_dp + (x * ((radius * 2) + level_circles_border_dp)), (ScreenHeight() / 2) - (total_circles_height / 2) + (level_circles_border_dp + (y * ((radius * 2) + level_circles_border_dp))), radius, getResources().getColor(R.color.white), this, false, SubTitle_Paint);
current_lvl++;
}
if (state == MENU) {
//draw title
Rect Title_Paint_bounds = new Rect();
Title_Paint.getTextBounds(getResources().getString(R.string.app_name), 0, getResources().getString(R.string.app_name).length(), Title_Paint_bounds);
canvas.drawText(getResources().getString(R.string.app_name), (ScreenWidth() / 2) - (Title_Paint_bounds.width() / 2), (top_border * 0.75f) + (Title_Paint_bounds.height() / 2), Title_Paint);
//draw buttons
btn_Play.draw(canvas);
//btn_Highscores.draw(canvas);
btn_Exit.draw(canvas);
btn_Rate.draw(canvas);
} else if (state == LEVELMENU) {
//draw levels
for (int i = 0; i < Level_Buttons.length; i++) {
Level_Buttons[i].draw(canvas);
}
答案 0 :(得分:0)
还有一个level_button.java的代码
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Typeface;
import com.neurondigital.nudge.Button;
import com.neurondigital.nudge.Screen;
import com.neurondigital.nudge.Sprite;
public class level_button extends Button {
int TopScore = 0;
boolean islocked = true;
Paint level_paint;
Screen screen;
Sprite lock, unlock;
public level_button(String text, int dpSize, Typeface font, int color, float x, float y, float radius, int BackColor, Screen screen, boolean world, Paint level_paint) {
super(text, dpSize, font, color, x, y, radius, BackColor, screen, world);
this.level_paint = level_paint;
this.screen = screen;
lock = new Sprite(BitmapFactory.decodeResource(screen.getResources(), R.drawable.lock), radius / 2);
unlock = new Sprite(BitmapFactory.decodeResource(screen.getResources(), R.drawable.unlock), radius / 2);
}
public void setTopScore(int TopScore) {
this.TopScore = TopScore;
if (TopScore > 0) {
setLock(false);
}
}
public void setLock(boolean islocked) {
this.islocked = islocked;
}
public String IntegerToScore(int score) {
return ((double) score / 1000) + screen.getResources().getString(R.string.time_suffix);
}
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
if (islocked)
lock.draw(canvas, x + width - lock.getWidth(), y + height - lock.getHeight());
else {
if (TopScore == 0)
unlock.draw(canvas, x + width - unlock.getWidth(), y + height - unlock.getHeight());
else
canvas.drawText(IntegerToScore(TopScore), x + (width / 2) - level_paint.measureText(IntegerToScore(TopScore)) * 0.5f, y + height + level_paint.getTextSize(), level_paint);
}
}
}