GridLayout,TableLayout或GridView中单元格的边界线? [英] Border Lines for cells in GridLayout, TableLayout, or GridView?

查看:126
本文介绍了GridLayout,TableLayout或GridView中单元格的边界线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的应用程序中的某些项目创建一个表格/网格,我希望每个单元格周围都有一个边框,以将这些项目划分出来,并使设置与该项目具有连贯的关联.此应用将在工业环境中使用,其中可能会有一些不熟悉Android的人需要使用此应用,因此尝试使其尽可能简单.

I am trying to create a table/grid for some items within my app and I would like to have a border around each cell to divide the items up and have a coherent association of the setting with the item. This app will be used in an industrial setting where there may be people unfamiliar with Android that need to use this, thus trying to make it as easy as possible.

表/网格将包含 TextView EditText Spinner Button ,并且还将可滚动(通过 ScrollView 父级).

The table/grid will contain TextView, EditText, Spinner, and Button, and will also be scrollable (via ScrollView parent).

我阅读了有关 GridView 的信息,发现它(似乎)只能以编程方式获取项目,如果我错了,请纠正我.我知道这是不必要的,因为我知道我想要什么物品以及在哪里.另外,我还没有尝试通过编程方式将项目添加到布局中,因此我认为我会首先尝试其他选项.另外, GridView 文档并没有说明如果自动显示边界线,或者您可以完全显示边界线,则采用另一种方法.

I read about the GridView and found that it (seems) to only be able to get items programmatically, please correct me if I am wrong. I felt that this was unnecessary since I know what items I want and where. Also, I have not tried adding items to a layout programmatically yet so I figured I would try the other options first. Also, the GridView documentation does not say one way or the other if border lines are automatically shown, or if you can have them shown at all.

我从 TableLayout 开始,能够使除边框线以外的所有内容都能正常工作.我试过 android:divider 来获取行,但是那行不通.我曾经想过要创建一堆具有黑色背景和〜2dp宽度/高度的 TextView ,以创建自己的边界线.但是,这感觉像是一个巨大的浪费.然后,我还阅读了 TableLayout文档,并发现了以下内容:"TableLayout容器不显示其行,列或单元格的边界线."

I started with a TableLayout and was able to get everything except the border lines to work. I tried android:divider to get the lines but that didn't work. One thought I had was to create a bunch of TextViews with black backgrounds and ~2dp widths/heights to make my own border lines. This feels like a huge waste though. Then I also read the TableLayout documentation and found this: "TableLayout containers do not display border lines for their rows, columns, or cells."

然后,我尝试了 GridLayout ,并获得了与 TableLayout 相同的结果.我尝试了 padding margins ,但这两个都不起作用.另外, GridLayout文档指出:网格已组成一组将视图区域分成多个单元的无限细线."

I then tried the GridLayout and had the same results as the TableLayout. I tried padding and margins, neither worked. Also, the GridLayout documentation states: "The grid is composed of a set of infinitely thin lines that separate the viewing area into cells."

我的问题是:

  1. TableLayout GridLayout 中是否缺少服装,可以通过xml给我边框线?

  1. Is there an attirbute that I missed in TableLayout or GridLayout that will give me border lines via the xml?

如果否,那么 GridView 会给我我想要的行吗?

If no, then will the GridView give me the lines I want?

我是否可以将所有以前提到的项目添加到 GridView ?

Will I be able to add all the perviously mentioned items I want to the GridView?

推荐答案

在TableLayout或GridLayout中是否缺少我想通过xml给我边框线的服装?

Is there an attirbute that I missed in TableLayout or GridLayout that will give me border lines via the xml?

否.

如果否,那么GridView会给我我想要的行吗?

If no, then will the GridView give me the lines I want?

否.

我可以将所有以前提到的项目添加到GridView吗?

Will I be able to add all the perviously mentioned items I want to the GridView?

是的,尽管像 Spinner 这样的东西能很好地工作,但我不能说.

Yes, though how well something like a Spinner will work, I can't say.

最简单的方法就是让 TableLayout GridLayout 的每个单元格成为包含以下内容的容器:该单元格的小部件,您可以在其中为容器提供一行的背景. ShapeDrawable 可能是在该背景下以XML定义,可以根据单元格的实际要求调整大小.

The simplest way, off the top of my head, to give you the lines you seek is to have each cell of the TableLayout or GridLayout be some container containing the widget(s) for that cell, where you give the container a background that is your line. A ShapeDrawable could be defined in XML for that background, which will be nicely resizeable based upon the actual requirements of the cell.

这篇关于GridLayout,TableLayout或GridView中单元格的边界线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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