Android的包装按钮 [英] Android Wrapping Buttons

查看:112
本文介绍了Android的包装按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全惊呆了,我无法找到有关如何做这种事。我怎么换图像的布局,只是下降到下一行..并继续这样做,直到所有的图像都被证明?我使用的是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;

这篇关于Android的包装按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆