Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
private void setSizes() { Display display = getWindowManager().getDefaultDisplay(); Point screenSize = new Point(); display.getSize(screenSize); int width = screenSize.x; int height = screenSize.y; mButtonSize = width / SIZE - 8; mButtonsField.setPadding(0, (height - (mButtonSize * SIZE)) / 2 - SIZE * 2, 0, (height - (mButtonSize * SIZE)) / 2 - SIZE * 2); } private void addButtons() { int count = 0; for (int i = 0; i < SIZE; i++) { LinearLayout layout = new LinearLayout(this); layout.setGravity(Gravity.CENTER); layout.setOrientation(LinearLayout.HORIZONTAL); mButtonsField.addView(layout); for (int j = 0; j < SIZE; j++) { LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); layoutParams.setMargins(1, 1, 1, 1); Button button = new Button(getBaseContext()); button.setId(ids[count]); button.setTag(i + "," + j); button.setWidth(mButtonSize); button.setHeight(mButtonSize); button.setTextColor(Color.WHITE); button.setTextSize(mButtonSize / SIZE ); button.setBackgroundColor(getResources().getColor(R.color.orange_cool)); button.setLayoutParams(layoutParams); Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/DROID.TTF"); button.setTypeface(typeface); mMovesTextView.setTypeface(typeface); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String[] rowCol = view.getTag().toString().split(","); int row = Integer.parseInt(rowCol[0]); int col = Integer.parseInt(rowCol[1]); char direction = canMove(row, col); if (direction != 'N') { movePuzzle(row, col, direction); if (SOUNDS) { if (mp.isPlaying()) { mp.stop(); } mp.start(); } mMoves++; setMovesText(); updateButtons(); if (checkIsWin()) { Intent winIntent = new Intent(GameBoardActivity.this, WinActivity.class).putExtra(MOVES_EXTRA, mMoves); startActivity(winIntent); finish(); } } } }); layout.addView(button); count++; } }