使用哪种android布局来分配可变宽度的按钮以填充屏幕? [英] Which android layout to use for distributing variable width buttons to fill a screen?

查看:154
本文介绍了使用哪种android布局来分配可变宽度的按钮以填充屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始使用Android,试图为孩子们编写一个集中注意力"游戏,将充满文本的屏幕分成多个按钮,填满整个屏幕(每个按钮一个字)

I am getting started with Android, trying to write a "concentration" game for kids where a screen full of text is separated into buttons, filling the screen (one word per button)

按钮应环绕在所包含的文本上,因此较长的单词将具有较长的按钮宽度.

The buttons should wrap to the contained text, so longer words will have longer button widths.

一旦一行填满,下一个按钮应该流到下一行,依此类推,直到整个屏幕上都充满了均匀间隔的可变宽度按钮.

Once a row fills up, the next button should flow to the next row, and so on, until the whole screen is filled with evenly spaced variable width buttons.

行数和每行中的按钮数根据屏幕尺寸(以及所提到的按钮宽度)而有所不同

The number of rows and number of buttons per row varies based on screen size (and as mentioned, button width)

我可以使用垂直线性布局,然后插入水平线性布局以包含行文本.但是,我看不出如何根据屏幕大小和文本大小来改变这些宽度和行数.

I could use a vertical linear layout, then insert horizontal linear layouts to contain the row text. However I don't see how to make those widths and number of rows vary based on the screen size and text size.

我想我需要创建自己的自定义布局,例如Spring中的FlowLayout-如果是这样,您能推荐一个有关此方法的教程吗?

I presume I need to create my own custom layout, something like FlowLayout in Spring - if so, can you recommend a tutorial for how to do so?

推荐答案

检查android的 API演示

Check android's API Demos

  • Animation->DefaultLayoutAnimation(例如)

LayoutAnimationsByDefault.java& layout_animations_by_default.xml(针对来源)

LayoutAnimationsByDefault.java & layout_animations_by_default.xml (for source)

它使用 GridLayout ,并对上述示例进行了一些修改,这对您的情况很有用..灵活,自API级别14开始提供,但已通过 support/compatibility提供库第三方库.

It uses GridLayout and with a bit of modifications of mentioned example, it will be useful for your case..It's flexible, it's available since API Level 14, but it's available trought support/compatibility library or 3rd party library .

希望这会有所帮助..干杯;)

Hope this will help.. Cheers ;)

这篇关于使用哪种android布局来分配可变宽度的按钮以填充屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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