android.widget.RelativeLayout#getWidth ( )源码实例Demo

下面列出了android.widget.RelativeLayout#getWidth ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Simple-Solitaire   文件: Maze.java
@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);
        }
    }
}
 
源代码2 项目: Simple-Solitaire   文件: Golf.java
public void setStacks(RelativeLayout layoutGame, boolean isLandscape, Context context) {
    //initialize the dimensions
    setUpCardWidth(layoutGame, isLandscape, 8, 9);

    //order stacks on the screen
    int spacing = setUpHorizontalSpacing(layoutGame, 7, 8);
    int startPos = layoutGame.getWidth() / 2 - 3 * spacing - (int) (3.5 * Card.width);
    //main stack
    stacks[8].setX(layoutGame.getWidth() - startPos - Card.width);
    stacks[8].view.setY((isLandscape ? Card.width / 4 : Card.width / 2) + 1);
    //discard stack
    stacks[7].setX(layoutGame.getWidth() - 2 * startPos - 2 * Card.width);
    stacks[7].setY(stacks[8].getY());
    //tableau stacks
    for (int i = 0; i < 7; i++) {
        stacks[i].setX(startPos + spacing * i + Card.width * i);
        stacks[i].setY(stacks[8].getY() + Card.height + (isLandscape ? Card.width / 4 : Card.width / 2) + 1);
    }
}
 
源代码3 项目: Simple-Solitaire   文件: Spider.java
public void setStacks(RelativeLayout layoutGame, boolean isLandscape, Context context) {
    //initialize the dimensions
    setUpCardWidth(layoutGame, isLandscape, 11, 12);
    int spacing = setUpHorizontalSpacing(layoutGame, 10, 11);
    int startPos = layoutGame.getWidth() - Card.width - 5 * Card.width / 2;
    //main stacks
    for (int i = 0; i < 5; i++) {
        stacks[18 + i].setX(startPos + i * Card.width / 2);
        stacks[18 + i].view.setY((isLandscape ? Card.width / 4 : Card.width / 2) + 1);
        stacks[18 + i].setImageBitmap(Stack.backgroundTransparent);
    }
    //foundation stacks
    for (int i = 0; i < 8; i++) {
        stacks[10 + i].setX(Card.width / 2 + i * Card.width / 2);
        stacks[10 + i].view.setY((isLandscape ? Card.width / 4 : Card.width / 2) + 1);
        stacks[10 + i].setImageBitmap(Stack.backgroundTransparent);
    }
    //tableau stacks
    startPos = layoutGame.getWidth() / 2 - 5 * Card.width - 4 * spacing - spacing / 2;
    for (int i = 0; i < 10; i++) {
        stacks[i].setX(startPos + spacing * i + Card.width * i);
        stacks[i].setY(stacks[18].getY() + Card.height + (isLandscape ? Card.width / 4 : Card.width / 2) + 1);
    }
    //set card families depending on settings
    loadCards();
}
 
源代码4 项目: Simple-Solitaire   文件: SimpleSimon.java
public void setStacks(RelativeLayout layoutGame, boolean isLandscape, Context context) {
    //initialize the dimensions
    setUpCardWidth(layoutGame, isLandscape, 11, 12);
    int spacing = setUpHorizontalSpacing(layoutGame, 10, 11);
    int startPos = layoutGame.getWidth() / 2 - 2 * Card.width - (int) (1.5 * spacing);

    //foundation stacks
    for (int i = 0; i < 4; i++) {
        stacks[10 + i].setX(startPos + spacing * i + Card.width * i);
        stacks[10 + i].view.setY((isLandscape ? Card.width / 4 : Card.width / 2) + 1);
    }

    //tableau stacks
    startPos = layoutGame.getWidth() / 2 - 5 * Card.width - 4 * spacing - spacing / 2;
    for (int i = 0; i < 10; i++) {
        stacks[i].setX(startPos + spacing * i + Card.width * i);
        stacks[i].setY(stacks[10].getY() + Card.height + (isLandscape ? Card.width / 4 : Card.width / 2) + 1);
    }
}
 
源代码5 项目: Simple-Solitaire   文件: Game.java
/**
 * 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);
}
 
源代码6 项目: Simple-Solitaire   文件: Yukon.java
public void setStacks(RelativeLayout layoutGame, boolean isLandscape, Context context) {
    //initialize the dimensions
    setUpCardDimensions(layoutGame, 9, 5);

    //order the stacks on the screen
    int spacingHorizontal = setUpHorizontalSpacing(layoutGame, 8, 9);
    int spacingVertical = min((layoutGame.getHeight() - 4 * Card.height) / 5, Card.width / 4);
    int startPos = (int) (layoutGame.getWidth() / 2 - 4 * Card.width - 3.5 * spacingHorizontal);
    //tableau stacks
    for (int i = 0; i <= 7; i++) {
        stacks[i].setX(startPos + spacingHorizontal * i + Card.width * i);
        stacks[i].setY(spacingVertical);
    }
    //foundation stacks
    for (int i = 8; i <= 10; i++) {
        stacks[i].setX(stacks[7].getX());
        stacks[i].setY(stacks[i - 1].getY() + Card.height + spacingVertical);
    }
    //nice background for foundation stacks
    for (int i = 7; i <= 10; i++) {
        stacks[i].setImageBitmap(Stack.background1);
    }
}
 
源代码7 项目: Simple-Solitaire   文件: Freecell.java
public void setStacks(RelativeLayout layoutGame, boolean isLandscape, Context context) {
    //initialize the dimensions
    setUpCardWidth(layoutGame, isLandscape, 9, 10);

    //order the stacks on the screen
    int spacing = setUpHorizontalSpacing(layoutGame, 8, 9);
    int startPos = layoutGame.getWidth() / 2 - 4 * Card.width - 3 * spacing - spacing / 2;
    //free cells and foundation stacks
    for (int i = 0; i < 8; i++) {
        stacks[8 + i].setX(startPos + spacing * i + Card.width * i);
        stacks[8 + i].view.setY((isLandscape ? Card.width / 4 : Card.width / 2) + 1);
    }
    //tableau stacks
    for (int i = 0; i < 8; i++) {
        stacks[i].setX(startPos + spacing * i + Card.width * i);
        stacks[i].setY(stacks[8].getY() + Card.height +
                (isLandscape ? Card.width / 4 : Card.width / 2));
    }
    //nice background for foundation stacks
    for (int i = 12; i < 16; i++) {
        stacks[i].setImageBitmap(Stack.background1);
    }
}
 
源代码8 项目: Simple-Solitaire   文件: FortyEight.java
public void setStacks(RelativeLayout layoutGame, boolean isLandscape, Context context) {

        setUpCardWidth(layoutGame, isLandscape, 8 + 1, 8 + 4);

        int spacing = setUpHorizontalSpacing(layoutGame, 8, 9);
        int startPos = (int) (layoutGame.getWidth() / 2 - 4 * Card.width - 3.5 * spacing);

        stacks[17].view.setX((int) (layoutGame.getWidth() / 2 + 3 * Card.width + 3.5 * spacing));
        stacks[17].view.setY((isLandscape ? Card.width / 4 : Card.width / 2) + 1);
        stacks[17].setImageBitmap(Stack.backgroundTalon);

        stacks[16].setX(stacks[17].getX() - spacing - Card.width);
        stacks[16].setY(stacks[17].getY());

        for (int i = 0; i < 8; i++) {
            stacks[8 + i].setX(startPos + i * (spacing + Card.width));
            stacks[8 + i].setY(stacks[17].getY() + Card.height + (isLandscape ? Card.width / 4 : Card.width / 2));
            stacks[8 + i].setImageBitmap(Stack.background1);
        }

        for (int i = 0; i < 8; i++) {
            stacks[i].setX(startPos + i * (spacing + Card.width));
            stacks[i].setY(stacks[8].getY() + Card.height + (isLandscape ? Card.width / 4 : Card.width / 2));
        }

    }
 
源代码9 项目: Simple-Solitaire   文件: Stack.java
/**
     * 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;
        }
    }
 
源代码10 项目: Simple-Solitaire   文件: GrandfathersClock.java
private void setStacksPortrait(RelativeLayout layoutGame) {
    //stacking shouldn't go over the clock layout
    setDirectionBorders(-1, -1, -1, -1, -1, -1, -1, -1);

    // initialize the dimensions
    setUpCardDimensions(layoutGame, 9, 10);

    //calculate spacing and start position of cards
    int spacing = setUpHorizontalSpacing(layoutGame, 8, 9);
    int verticalSpacing = setUpVerticalSpacing(layoutGame, 9, 10);

    //first foundation stacks in a circle
    int startPosX = (int) (layoutGame.getWidth() / 2 - 2.5 * Card.width - 2 * spacing);
    int startPosY = Card.width / 2;

    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);

    //deal stack
    stacks[20].setX(stacks[10].getX());
    stacks[20].setY(stacks[13].getY());

    //then tableau stacks
    startPosX = layoutGame.getWidth() / 2 - spacing / 2 - 4 * Card.width - 3 * spacing;
    startPosY = (int) stacks[17].getY() + Card.height + Card.height / 2;

    for (int i = 0; i < 8; i++) {
        stacks[i].setX(startPosX + spacing * i + Card.width * i);
        stacks[i].setY(startPosY);
    }
}
 
源代码11 项目: Simple-Solitaire   文件: GrandfathersClock.java
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);
    }
}
 
源代码12 项目: Simple-Solitaire   文件: DummyGame.java
public void setStacks(RelativeLayout layoutGame, boolean isLandscape, Context context) {

        //use this to set the cards width according to last two values.
        //second last is for portrait mode, last one for landscape.
        //the layout width will be divided by these values according to orientation to use as card widths.
        //Card height is 1.5*widht and the dimensions are applied to every card and stack
        //
        //use values as +1, +2 added to the number of stacks in the longest row of your layout, so there is
        //enough space left to use as spacing between the stacks.
        setUpCardWidth(layoutGame, isLandscape, 7 + 1, 7 + 2);

        //use this to automatically set up the dimensions (then the call above isn't nessessary).
        //It will take the layout and a value for width and one value for height. The values
        //represent the limiting values for the orientation. For example here: 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
        setUpCardDimensions(layoutGame, 7, 4);

        //now we order the stacks on the field. First calculate a spacing variable, to know how much
        //space will be between the stacks. It just uses the layout width minus the number of stacks
        //in a row, divided with the number of spaces between the stacks (which should be the number
        //of stacks +1) It also uses a maximum value of Card.widht/2, so the cards won't be too far apart
        int spacing = setUpHorizontalSpacing(layoutGame, 7, 8);

        //now getHighScore the start position to place the stacks, so they are centered around the middle of
        //the screen. I use this way: Get the half of the layout width, minus how many stacks are on the
        //left to it times the card width, minus how many spacings are left to it times the spacing
        //width. (Do not use the spacing from the left screen edge to the first stack).
        //So it should look like this:
        int startPos = layoutGame.getWidth() / 2 - 3 * Card.width - 3 * spacing;
        //Then set the stack coordinates like this:
        //X cor is the start pos + loop index times (spacing + card width)
        //Y cor can be like in the example code. In landscape use a bit less spacing from the
        //screen edge. The +1 is only so Android Studio doesnt show an error
        for (int i = 0; i < 6; i++) {
            stacks[i].setX(startPos + i * (spacing + Card.width));
            stacks[i].view.setY((isLandscape ? Card.width / 4 : Card.width / 2) + 1);
        }
        //Also set other stacks like the main pile or something
        stacks[6].setX(stacks[0].getX());
        stacks[6].setY(stacks[0].getY() + Card.height + spacing);

        //Last step: Set the drawables of the stacks. Default one is just gray.
        //So maybe show on some a big A for ace or make them transparent or something
        stacks[6].setImageBitmap(Stack.background1);               //shows an A
        stacks[6].setImageBitmap(Stack.backgroundTalon);           //shows a circle arrow
        stacks[6].setImageBitmap(Stack.backgroundTransparent);     //no background at all
    }
 
源代码13 项目: Simple-Solitaire   文件: NapoleonsTomb.java
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]);
    }
 
源代码14 项目: Simple-Solitaire   文件: AcesUp.java
public void setStacks(RelativeLayout layoutGame, boolean isLandscape, Context context) {

        setUpCardWidth(layoutGame, isLandscape, 7 + 1, 7 + 2);

        int spacing = setUpHorizontalSpacing(layoutGame, 7, 8);

        int startPos = (int) (layoutGame.getWidth() / 2 - 3.5 * Card.width - 2.5 * spacing);

        stacks[4].setX(startPos);
        stacks[4].view.setY((isLandscape ? Card.height / 4 : Card.height / 2) + 1);

        for (int i = 0; i < 4; i++) {
            stacks[i].setX(stacks[4].getX() + spacing + Card.width * 3 / 2 + i * (spacing + Card.width));
            stacks[i].setY(stacks[4].getY());
        }

        stacks[5].setX(stacks[3].getX() + Card.width + Card.width / 2 + spacing);
        stacks[5].setY(stacks[4].getY());
    }
 
源代码15 项目: Simple-Solitaire   文件: Calculation.java
public void setStacks(RelativeLayout layoutGame, boolean isLandscape, Context context) {

        setUpCardWidth(layoutGame, isLandscape, 7 + 1, 7 + 2);

        int spacing = setUpHorizontalSpacing(layoutGame, 7, 8);

        int startPosX = (int) (layoutGame.getWidth() - 6.5 * Card.width - 4 * spacing) / 2;
        int startPosY = isLandscape ? Card.height / 4 : Card.height / 2;

        //foundation stacks
        for (int i = 0; i < 4; i++) {
            stacks[4 + i].setX(startPosX + i * (spacing + Card.width));
            stacks[4 + i].setY(startPosY);
        }

        //tableau stacks
        for (int i = 0; i < 4; i++) {
            stacks[i].setX(startPosX + i * (spacing + Card.width));
            stacks[i].setY(startPosY + Card.height + (isLandscape ? Card.height / 8 : Card.height / 4) + 1);
        }

        //trash
        stacks[8].setX(stacks[3].getX() + Card.width + Card.width / 2);
        stacks[8].setY(stacks[4].getY());

        //stock
        stacks[9].setX(stacks[8].getX() + Card.width + spacing);
        stacks[9].setY(stacks[4].getY());

        stacks[4].setImageBitmap(Stack.background1);
        stacks[5].setImageBitmap(Stack.background2);
        stacks[6].setImageBitmap(Stack.background3);
        stacks[7].setImageBitmap(Stack.background4);

        //generate the textViews over the foundation stacks

        addTextViews(4, Card.width, layoutGame, context);

        for (int i = 0; i < 4; i++) {
            textViewPutAboveStack(i, stacks[4 + i]);
        }
    }
 
源代码16 项目: Simple-Solitaire   文件: TriPeaks.java
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());
    }
 
源代码17 项目: Simple-Solitaire   文件: Klondike.java
public void setStacks(RelativeLayout layoutGame, boolean isLandscape, Context context) {

        // initialize the dimensions
        setUpCardWidth(layoutGame, isLandscape, 8, 10);

        //calculate spacing and start position of cards
        int spacing = setUpHorizontalSpacing(layoutGame, 7, 8);
        int startPos = layoutGame.getWidth() / 2 - Card.width / 2 - 3 * Card.width - 3 * spacing;

        //first order the foundation stacks
        for (int i = 0; i < 4; i++) {
            stacks[7 + i].setX(startPos + spacing * i + Card.width * i);
            stacks[7 + i].view.setY((isLandscape ? Card.width / 4 : Card.width / 2) + 1);
        }

        //then the trash and main stacks
        startPos = layoutGame.getWidth() - 2 * spacing - 3 * Card.width;
        for (int i = 0; i < 3; i++) {
            stacks[11 + i].setX(startPos + Card.width / 2 * i);
            stacks[11 + i].view.setY((isLandscape ? Card.width / 4 : Card.width / 2) + 1);
        }
        stacks[14].setX(stacks[13].getX() + Card.width + spacing);
        stacks[14].setY(stacks[13].getY());

        //now the tableau stacks
        startPos = layoutGame.getWidth() / 2 - Card.width / 2 - 3 * Card.width - 3 * spacing;
        for (int i = 0; i < 7; i++) {
            stacks[i].setX(startPos + spacing * i + Card.width * i);
            stacks[i].setY(stacks[7].getY() + Card.height +
                    (isLandscape ? Card.width / 4 : Card.width / 2));
        }

        //also set backgrounds of the stacks
        for (Stack stack : stacks) {
            if (stack.getId() > 6 && stack.getId() <= 10) {
                stack.setImageBitmap(Stack.background1);
            } else if (stack.getId() > 10 && stack.getId() <= 13) {
                stack.setImageBitmap(Stack.backgroundTransparent);
            } else if (stack.getId() == 14) {
                stack.setImageBitmap(Stack.backgroundTalon);
            }
        }
    }
 
源代码18 项目: Simple-Solitaire   文件: Canfield.java
public void setStacks(RelativeLayout layoutGame, boolean isLandscape, Context context) {

        // initialize the dimensions
        setUpCardWidth(layoutGame, isLandscape, 8, 10);

        //calculate spacing and startposition of cards
        int spacing = setUpHorizontalSpacing(layoutGame, 7, 8);
        int startPos = layoutGame.getWidth() / 2 - Card.width / 2 - 3 * Card.width - 3 * spacing;

        //first order the foundation stacks
        for (int i = 0; i < 4; i++) {
            stacks[5 + i].setX(startPos + spacing * i + Card.width * i);
            stacks[5 + i].view.setY((isLandscape ? Card.width / 4 : Card.width / 2) + 1);
        }

        //then the trash and main stacks
        startPos = layoutGame.getWidth() - 2 * spacing - 3 * Card.width;
        for (int i = 0; i < 3; i++) {
            stacks[9 + i].setX(startPos + Card.width / 2 * i);
            stacks[9 + i].view.setY((isLandscape ? Card.width / 4 : Card.width / 2) + 1);
        }
        stacks[12].setX(stacks[11].getX() + Card.width + spacing);
        stacks[12].setY(stacks[11].getY());

        stacks[4].setX(stacks[12].getX());
        stacks[4].setY(stacks[12].getY() + Card.height +
                (isLandscape ? Card.width / 4 : Card.width / 2));

        //now the tableau stacks
        startPos = layoutGame.getWidth() / 2 - Card.width / 2 - 3 * Card.width - 3 * spacing;
        for (int i = 0; i < 4; i++) {
            stacks[i].setX(startPos + spacing * i + Card.width * i);
            stacks[i].setY(stacks[7].getY() + Card.height +
                    (isLandscape ? Card.width / 4 : Card.width / 2));
        }

        //also set backgrounds of the stacks
        for (int i = 9; i < 12; i++) {
            stacks[i].setImageBitmap(Stack.backgroundTransparent);
        }

        stacks[12].setImageBitmap(Stack.backgroundTalon);
    }
 
源代码19 项目: Simple-Solitaire   文件: Game.java
/**
 * Use this to set the cards width according to the last two values.
 * second last is for portrait mode, last one for landscape.
 * the game width will be divided by these values according to orientation to use as card widths.
 * Card height is 1.5*width and the dimensions are applied to every card and stack
 *
 * @param layoutGame     The layout, where the cards are located in
 * @param isLandscape    Shows if the phone is currently in landscape mode
 * @param portraitValue  The limiting number of card in the biggest row of the layout
 * @param landscapeValue The limiting number of cards in the biggest column of the layout
 */
protected void setUpCardWidth(RelativeLayout layoutGame, boolean isLandscape, int portraitValue, int landscapeValue) {
    Card.width = isLandscape ? layoutGame.getWidth() / (landscapeValue) : layoutGame.getWidth() / (portraitValue);
    Card.height = (int) (Card.width * 1.5);
    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);
}
 
源代码20 项目: Simple-Solitaire   文件: Pyramid.java
public void setStacks(RelativeLayout layoutGame, boolean isLandscape, Context context) {

        setUpCardDimensions(layoutGame, 7 + 1, 5 + 1);

        int spacing = setUpHorizontalSpacing(layoutGame, 7, 8);

        int index = 0;
        for (int i = 0; i < 7; i++) {

            int startPosX = layoutGame.getWidth() / 2 - (i + 1) * Card.width / 2 - i * spacing / 2;
            int startPosY = (isLandscape ? Card.width / 4 : Card.width / 2) + i * Card.height / 2;

            for (int j = 0; j < i + 1; j++) {

                stackAboveID[index] = ((i + 1) * (i + 2)) / 2 + j;

                stacks[index].setX(startPosX + j * (spacing + Card.width));
                stacks[index].setY(startPosY);
                stacks[index].setImageBitmap(Stack.backgroundTransparent);

                index++;
            }
        }

        stacks[28].setX(stacks[21].getX() + Card.width / 2 + spacing / 2);
        stacks[28].setY(stacks[21].getY() + Card.height + (isLandscape ? Card.width / 4 : Card.width / 2));

        stacks[29].setX(stacks[24].getX() + Card.width / 2);
        stacks[29].setY(stacks[28].getY());

        stacks[31].setX(stacks[29].getX() + Card.width + spacing);
        stacks[31].setY(stacks[28].getY());
        setArrow(stacks[31]);

        stacks[30].setX(stacks[31].getX() + Card.width + spacing);
        stacks[30].setY(stacks[28].getY());
    }