Java Code Examples for android.widget.RelativeLayout#getHeight()
The following examples show how to use
android.widget.RelativeLayout#getHeight() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Maze.java From Simple-Solitaire with GNU General Public License v3.0 | 6 votes |
@Override public void setStacks(RelativeLayout layoutGame, boolean isLandscape, Context context) { setUpCardDimensions(layoutGame, COLS + 1, ROWS + 1); int spacing = min( setUpHorizontalSpacing(layoutGame, COLS, COLS + 1), setUpVerticalSpacing(layoutGame, ROWS, ROWS + 1)); int startX = (layoutGame.getWidth() - COLS * Card.width - (COLS + 1) * spacing) / 2; int startY = (layoutGame.getHeight() - ROWS * Card.height - (ROWS + 1) * spacing) / 2; for (int row = 0; row < ROWS; ++row) { for (int col = 0; col < COLS; ++col) { int stackIdx = row * COLS + col; stacks[stackIdx].setX(startX + (col + 1) * spacing + col * Card.width); stacks[stackIdx].setY(startY + (row + 1) * spacing + row * Card.height); } } }
Example 2
Source File: Game.java From Simple-Solitaire with GNU General Public License v3.0 | 6 votes |
/** * use this to automatically set up the dimensions (then the call of setUpCardWidth() isn't necessary). * It will take the layout, a value for width and a value for height. The values * represent the limiting values for the orientation. For example : There are 7 rows, so 7 * stacks have to fit on the horizontal axis, but also 4 cards in the height. The method uses * these values to calculate the right dimensions for the cards, so everything fits fine on the screen * * @param layoutGame The layout, where the cards are located in * @param cardsInRow The limiting number of card in the biggest row of the layout * @param cardsInColumn The limiting number of cards in the biggest column of the layout */ protected void setUpCardDimensions(RelativeLayout layoutGame, int cardsInRow, int cardsInColumn) { int testWidth1, testHeight1, testWidth2, testHeight2; testWidth1 = layoutGame.getWidth() / cardsInRow; testHeight1 = (int) (testWidth1 * 1.5); testHeight2 = layoutGame.getHeight() / cardsInColumn; testWidth2 = (int) (testHeight2 / 1.5); if (testHeight1 < testHeight2) { Card.width = testWidth1; Card.height = testHeight1; } else { Card.width = testWidth2; Card.height = testHeight2; } RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(Card.width, Card.height); for (Card card : cards) card.view.setLayoutParams(params); for (Stack stack : stacks) stack.view.setLayoutParams(params); }
Example 3
Source File: PullToRefreshLayout.java From PullToRefresh with Apache License 2.0 | 6 votes |
@Override public void onPull(View v, float pullDistance, int which) { // TODO Auto-generated method stub // 动画总帧数 int frames = mGifDrawable.getNumberOfFrames(); RelativeLayout headView = (RelativeLayout) v .findViewById(R.id.head_view); int headViewHeight = headView.getHeight(); // 算出下拉过程中对应的动画进度 float progress = Math.abs(pullDistance % headViewHeight / headViewHeight); // 当前播放帧 int currentFrame = (int) (frames * progress) + 1; // 当前帧与上一帧不同时才进行播放,保证流畅度 if (lastFramePosition != currentFrame) { // 需要进行动画重置,否则不能够自由地定位到每一帧 mGifDrawable.reset(); mGifDrawable.seekToFrame(currentFrame); lastFramePosition = currentFrame; } }
Example 4
Source File: Stack.java From Simple-Solitaire with GNU General Public License v3.0 | 5 votes |
/** * Sets the screen dimensions as a border, so cards on this stack won't leave the screen. * * @param layoutGame The layout, where the cards are located in */ public void setSpacingMax(RelativeLayout layoutGame) { /* RelativeLayout container = (RelativeLayout) layoutGame.getParent(); RelativeLayout overlay = container.findViewById(R.id.mainRelativeLayoutGameOverlay); ImageView menuResize = overlay.findViewById(R.id.mainImageViewResize); */ switch (spacingDirection) { case NONE: default: break; case DOWN: spacingMax = (float) (layoutGame.getHeight() - Card.height); // - menuResize.getHeight()); break; case UP: spacingMax = 0; break; case LEFT: if (leftHandedModeEnabled()) { spacingMax = layoutGame.getWidth() - Card.width; } else { spacingMax = 0; } break; case RIGHT: if (leftHandedModeEnabled()) { spacingMax = 0; } else { spacingMax = layoutGame.getWidth() - Card.width; } break; } }
Example 5
Source File: GrandfathersClock.java From Simple-Solitaire with GNU General Public License v3.0 | 4 votes |
private void setStacksLandscape(RelativeLayout layoutGame) { //stacking shouldn't go over the clock layout setDirectionBorders(4, 4, 4, 4, -1, -1, -1, -1); // initialize the dimensions setUpCardDimensions(layoutGame, 12, 6); //calculate spacing and start position of cards int spacing = setUpHorizontalSpacing(layoutGame, 11, 12); int verticalSpacing = setUpVerticalSpacing(layoutGame, 5, 7); //foundation stacks in a circle int startPosX = (layoutGame.getWidth() - 10 * Card.width - 9 * spacing) / 2 + Card.width / 2; int startPosY = layoutGame.getHeight() / 2 - Card.height / 2 - 7 * verticalSpacing - Card.height; stacks[8].setX(startPosX); stacks[8].setY(startPosY + 6 * verticalSpacing); stacks[9].setX(startPosX + Card.width + spacing); stacks[9].setY(startPosY + 3 * verticalSpacing); stacks[10].setX(startPosX + 2 * Card.width + 2 * spacing); stacks[10].setY(startPosY); stacks[11].setX(startPosX + 3 * Card.width + 3 * spacing); stacks[11].setY(startPosY + 3 * verticalSpacing); stacks[12].setX(startPosX + 4 * Card.width + 4 * spacing); stacks[12].setY(startPosY + 6 * verticalSpacing); // stacks[13].setX(stacks[8].getX() - Card.width / 2); stacks[13].setY(stacks[8].getY() + Card.height + verticalSpacing); stacks[14].setX(stacks[12].getX() + Card.width / 2); stacks[14].setY(stacks[12].getY() + Card.height + verticalSpacing); // startPosY = (int) (stacks[13].getY() + Card.height + verticalSpacing); stacks[15].setX(stacks[8].getX()); stacks[15].setY(startPosY); stacks[16].setX(stacks[9].getX()); stacks[16].setY(startPosY + 3 * verticalSpacing); stacks[17].setX(stacks[10].getX()); stacks[17].setY(startPosY + 6 * verticalSpacing); stacks[18].setX(stacks[11].getX()); stacks[18].setY(startPosY + 3 * verticalSpacing); stacks[19].setX(stacks[12].getX()); stacks[19].setY(startPosY); startPosX = (int) (stacks[14].getX() + Card.width + 2 * spacing); startPosY = Card.height / 2; //deal stack stacks[20].setX(stacks[10].getX()); stacks[20].setY(stacks[13].getY()); //tableau stacks for (int i = 0; i < 4; i++) { stacks[i].setX(startPosX + spacing * i + Card.width * i); stacks[i].setY(startPosY); } for (int i = 0; i < 4; i++) { stacks[4 + i].setX(startPosX + spacing * i + Card.width * i); stacks[4 + i].setY((layoutGame.getHeight() - Card.height) / 2 + Card.height / 2); } }
Example 6
Source File: NapoleonsTomb.java From Simple-Solitaire with GNU General Public License v3.0 | 4 votes |
public void setStacks(RelativeLayout layoutGame, boolean isLandscape, Context context) { // initialize the dimensions setUpCardDimensions(layoutGame, 8, 6); //calculate spacing and start position of cards int spacing = setUpHorizontalSpacing(layoutGame, 4, 4); int spacingVertical = setUpVerticalSpacing(layoutGame, 3, 2); int startPosX = (int) ((layoutGame.getWidth() - Card.width * 5 - spacing * 3) / 2.0); int startPosY = (int) ((layoutGame.getHeight() - Card.height * 4 - spacing * 2) / 2.0); //first row stacks[4].setX(startPosX + Card.width / 2); stacks[4].view.setY(startPosY + Card.height / 2); stacks[0].setX(stacks[4].getX() + spacing + Card.width); stacks[0].view.setY(startPosY); stacks[5].setX(stacks[0].getX() + spacing + Card.width); stacks[5].view.setY(startPosY + Card.height / 2); //second row stacks[1].setX(startPosX); stacks[1].setY(stacks[4].getY() + Card.height + spacingVertical); stacks[8].setX(stacks[0].getX()); stacks[8].setY(stacks[1].getY()); stacks[2].setX(stacks[5].getX() + Card.width / 2); stacks[2].setY(stacks[1].getY()); //third row stacks[6].setX(stacks[4].getX()); stacks[6].setY(stacks[1].getY() + Card.height + spacingVertical); stacks[3].setX(stacks[0].getX()); stacks[3].setY(stacks[6].getY() + Card.height / 2); stacks[7].setX(stacks[5].getX()); stacks[7].setY(stacks[6].getY()); //main + discard stack stacks[10].setX(stacks[5].getX() + spacing * 2 + Card.width); stacks[10].setY(stacks[5].getY() + Card.height / 2 + spacingVertical / 2); stacks[9].setX(stacks[10].getX()); stacks[9].setY(stacks[10].getY() + Card.height + spacingVertical); //also set backgrounds of the stacks for (Stack stack : stacks) { if (stack.getId() > 3 && stack.getId() <= 7) { stack.setImageBitmap(Stack.background7); } else if (stack.getId() == 8) { stack.setImageBitmap(Stack.background6); } else if (stack.getId() == 10) { stack.setImageBitmap(Stack.backgroundTalon); } } //generate the textViews over the last foundation stack addTextViews(1, Card.width, layoutGame, context); textViewPutAboveStack(0, stacks[8]); }
Example 7
Source File: TriPeaks.java From Simple-Solitaire with GNU General Public License v3.0 | 4 votes |
public void setStacks(RelativeLayout layoutGame, boolean isLandscape, Context context) { setUpCardDimensions(layoutGame, 11, 6); int spacing = setUpHorizontalSpacing(layoutGame, 10, 11); int startPosX = (int) (layoutGame.getWidth() / 2 - 3.5 * Card.width - 3 * spacing); int startPosY = (int) ((layoutGame.getHeight() - Card.height * 4.25 - (isLandscape ? Card.height / 4 : Card.height / 2)) / 2); for (int i = 0; i < 28; i++) { if (i == 3) { startPosX = (int) (layoutGame.getWidth() / 2 - 4 * Card.width - 3.5 * spacing); startPosY = (int) ((layoutGame.getHeight() - Card.height * 4.25 - (isLandscape ? Card.height / 4 : Card.height / 2)) / 2 + 0.75 * Card.height); } else if (i == 9) { startPosX = (int) (layoutGame.getWidth() / 2 - 4.5 * Card.width - 4 * spacing); startPosY = (int) ((layoutGame.getHeight() - Card.height * 4.25 - (isLandscape ? Card.height / 4 : Card.height / 2)) / 2 + 1.5 * Card.height); } else if (i == 18) { startPosX = (int) (layoutGame.getWidth() / 2 - 5 * Card.width - 4.5 * spacing); startPosY = (int) ((layoutGame.getHeight() - Card.height * 4.25 - (isLandscape ? Card.height / 4 : Card.height / 2)) / 2 + 2.25 * Card.height); } if (i > 3 && i < 9 && (i - 1) % 2 == 0) startPosX += Card.width + spacing; stacks[i].setX(startPosX); stacks[i].setY(startPosY); stacks[i].setImageBitmap(Stack.backgroundTransparent); if (i < 3) startPosX += 3 * Card.width + 3 * spacing; else startPosX += Card.width + spacing; } stacks[28].setX(layoutGame.getWidth() / 2 - Card.width - spacing); stacks[28].setY(stacks[18].getY() + Card.height + (isLandscape ? Card.height / 4 : Card.height / 2)); stacks[29].setX(stacks[28].getX() + 2 * spacing + Card.width); stacks[29].setY(stacks[28].getY()); }