android - 动态创建多行按钮列表

标签 android list android-layout button

我想创建一个多行按钮列表。像这样的东西:
enter image description here
但我想动态地(在代码中)做到这一点。有没有办法告诉布局自动执行此操作?或者我必须自己使用 RelativeLayout.LayoutParams 来完成此操作。我可以通过代码做到这一点,但我应该控制很多事情,我想知道是否有另一种更简单的方法来做到这一点。例如告诉布局在当前行已满时在下一行添加元素!

最佳答案

您也可以使用 LinearLayout 来做到这一点,并使用权重使所有按钮的大小相同。

关于你的问题:

i can do this by code but i should control so many things and i was wondering if there is another easier way to do this. for example tell layout to add elements in the next row when the current one is full!

如果您测量屏幕宽度和高度并使用 View 类中的函数来确定该特定 View 及其 subview 的细节,这就有可能实现。

备选

但是正如评论中提到的,您可以使用其他 View 来解决您的问题,例如 GridView。

关于android - 动态创建多行按钮列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11842519/

相关文章:

android - 如何在 ListView 高度设置为 fill_parent 后显示其他 View

java - 错误 : android. widget.LinearLayout cannot be cast to android.widget.EditText 的问题

Android - 读取/写入在线 mysql 数据库

java - 使用 Java gcm-server 向主题发送消息

android - 从 ionic 生成非调试 apk

python - 有效地确定列表中的三个项目中的两个是否相同

Android:Viewpager 内的 SwipeRefreshLayout 内的搜索栏

css - IE8水平列表的问题

javascript - 如何获取json对象标题

android - 输入耗时(一些对话?)