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

查看:69
本文介绍了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.

表格/网格将包含 TextViewEditTextSpinnerButton,并且还将包含可滚动(通过 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 相同的结果.我尝试了 paddingmargins,都没有奏效.此外,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. 是否有我在 TableLayoutGridLayout 中遗漏的属性会通过 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.

最简单的方法是让 TableLayoutGridLayout 的每个单元格成为包含该单元格的小部件,您可以在其中为容器提供一个背景作为您的线条.一个 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天全站免登陆