Android的包装按钮按钮、Android

2023-09-06 17:11:11 作者:一杯空气

我完全惊呆了,我无法找到有关如何做这种事。我怎么换图像的布局,只是下降到下一行..并继续这样做,直到所有的图像都被证明?我使用的是80×80的图像,按钮以及何时然而,许多可容纳在同一行,我想给他们换到下一行并继续。当那些已经达到了目的,我希望它再次换行。

I'm completely shocked that I can't find anything about how to do this. How do I wrap images in a layout to just drop down to the next line.. and continue to do so until all of the images have been shown? I'm using 80x80 images as buttons and when however many can fit on one line, I want it to wrap them to the next line and continue. When those have reached the end, I want it to wrap again.

可有人请告诉我如何建立这个布局?谢谢你。

Can someone please show me how to build this layout? Thank you.

推荐答案

在12 API和更早,你想要的:

In API 12 and earlier, you want:

public static final int BUTTON_WIDTH = 80;
public static final int BUTTON_HEIGHT = 80;
public static final int SPACING = 8;

Display display = getWindowManager().getDefaultDisplay();
public int screenWidth = display.getWidth();
public int screenHeight = display.getHeight();    

//somewhere a drawButton(int y, int x) should be defined

for (int i = 0, i < screenHeight, i += (BUTTON_HEIGHT + SPACING)) {
    for (int j = 0, j < screenWidth, j += (BUTTON_WIDTH + SPACING)) {
        drawButton(i, j);
    }
}

在API 13及更高版本,替换为以下5-7行:

In API 13 and later, replace lines 5-7 with the following:

Point screen = new Point();
getWindowManager().getDefaultDisplay().getSize(screen);

public int screenWidth = screen.x;
public int screenHeight = screen.y;