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.
The table/grid will contain TextView
, EditText
, Spinner
, and Button
, and will also be scrollable (via ScrollView
parent).
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.
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 TextView
s 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."
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."
My questions are:
Is there an attirbute that I missed in TableLayout
or GridLayout
that will give me border lines via the xml?
If no, then will the GridView
give me the lines I want?
Will I be able to add all the perviously mentioned items I want to the GridView
?
I was actually able to achieve the desired look by setting the android:background="#000000"
within the GridLayout
view and then in the child items I set the android:background="#8CDD81"
(just some green color) and combined with android:layout_margin="2dp"
I was able to get the "grid" lines that I wanted. Thanks to CommonsWare though for getting me thinking in a new direction that turned into a solution.
EDIT:
This does not work quite as anticipated. You need the android:layout_alignLeft/Right
which are only available via RelativeLayout
in order to get just the right width on the child items. Haven't tested this yet using this idea, child items
within RelativeLayout
within GridLayout
.