简体   繁体   English

Android Widget中的行和列布局

[英]Rows and Columns layout in Android Widget

Things are simple, I want to make a widget with 4 lines and 4 rows in it, on each cell there would be a click-able image and an action set by the user via the Settings page. 事情很简单,我想制作一个包含4行和4行的小部件,每个单元格上都有一个可点击的图像和用户通过“设置”页面设置的动作。

The layout is like this: 布局是这样的:

在此输入图像描述

What layout element is recommended to be used for this scenario ? 建议将哪种布局元素用于此方案? Should I use a GridView, TableLayout, more Linearlayouts ? 我应该使用GridView,TableLayout,更多的Linearlayouts吗? Keep in mind that the spacing between items must be the same. 请记住,项目之间的间距必须相同。 I want to make it as light as possible. 我希望尽可能轻松。 So, what layout ? 那么,什么布局?

If I decide to use a GridView do you have any simple tutorial about this? 如果我决定使用GridView你有任何关于这个的简单教程吗? I can't manage to find a way of accessing the GridView from AppWidgetProvider and set it's Adapter. 我无法找到一种从AppWidgetProvider访问GridView并设置它的适配器的方法。 Thank you. 谢谢。

LE: It seems that GridView is supported starting from Android 3.0.. please correct me if I'm wrong. LE:似乎从Android 3.0开始支持GridView ..如果我错了,请纠正我。 In this case the only remaining thing to do is add 16 images and for each image add a onClickListener ? 在这种情况下,唯一剩下的事情是添加16个图像,并为每个图像添加一个onClickListener? Brrr... BRRR ...

If you use a GridView then half of your work is done for you - The only layout and formatting elements you need to consider are on a Global (GridView) and Item level. 如果您使用GridView,那么您的一半工作就完成了 - 您需要考虑的唯一布局和格式元素是Global(GridView)和Item级别。

Using a GridView will also give your Scrolling functionality and the ability to change your row/columns count based on your device (4x4 on tablet, perhaps 2x8 on a phone). 使用GridView还可以提供滚动功能,并能够根据您的设备更改行/列数(平板电脑上4x4,手机上可能是2x8)。

Creating an extension of BaseAdapter to attach the Grid's children will also give you the flexibility to check items, multi select and will allow you to quickly modify the implementation in future by adding and removing items at will. 创建BaseAdapter的扩展以附加Grid的子项也将使您可以灵活地检查项目,多选,并允许您通过随意添加和删除项目来快速修改实现。

If this is simply a 4x4 grid which will always ALWAYS remain the same independent of device and each "Item" will always be the same, Use a RelativeLayout as it will be the most lightweight and efficient ViewGroup. 如果这只是一个4x4网格,它总是始终保持独立于设备,并且每个“Item”将始终相同,请使用RelativeLayout ,因为它将是最轻量级和最高效的ViewGroup。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM