I am making a native android app, I want to draw a vertical line between two columns in a grid-layout, is there any way i can do this ?? In the following screenshot, you can see the lines between cells and between the column. Basically, i just want to display the grid with my own custom style. This is the link to see the screenshots, apparently stack wont let me post a pic
Asked
Active
Viewed 4,648 times
0
-
Check [this answer](http://stackoverflow.com/a/23891978/2826147) – Amit Vaghela Mar 03 '16 at 09:46
-
Go below link you may find your solution http://stackoverflow.com/questions/12109126/android-gridview-row-dividers-separators – Dixit Panchal Mar 03 '16 at 09:58
-
A lot of good solutions. what do you think if we went 1px ppl instead of 1dp. the line will look nice and thinner on devices with high specs. does this work? – hasan Mar 03 '16 at 10:06
4 Answers
3
Add verticalSpacing in your grid layout and set GridView background as the color of line you want.
<GridView
android:id="@+id/grid_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#DADADA"
android:verticalSpacing="1dp"
android:numColumns="2" />
1
You can add a Vertical line like this -
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#000000" />
You can set the height as per requirement and can add margin to the above View if required

Asutosh Panda
- 1,463
- 2
- 13
- 25
-
I use this solution usually. but, I don't like it for one reason. the line is thik and doesn't look nice. how we can do a thinner line than 1 dp. – hasan Mar 03 '16 at 09:56
-
-
even that you use a grid layout. you can put it in a framelayout along with this suggested view. – hasan Mar 03 '16 at 09:58
-
@hasan83 , you must be having an XML layout for grid items. Just use this code there, you will get a vertical line. – Asutosh Panda Mar 04 '16 at 14:01
0
if you use two LinearLayouts side by side you can use the frameworks divider function with an ease:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:divider="?android:listDivider"
android:dividerPadding="2.5dp"
android:orientation="horizontal"
android:showDividers="middle"
android:weightSum="2" > ... </LinearLayout>
See also: http://developer.android.com/reference/android/widget/LinearLayout.html

and_dev
- 3,723
- 1
- 20
- 28
0
Maybe something like this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_5sdp"
android:layout_alignParentBottom="true"
android:divider="?android:listDivider"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal"
android:showDividers="middle"
android:weightSum="1" >
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="@dimen/_5sdp"
android:rowCount="2"
android:columnCount="1">
<TextView
android:text="Qty"
/>
<TextView
android:id="@+id/txtQtyProduct"
android:layout_gravity="center"
android:text="1"/>
</GridLayout>
</LinearLayout>

Selvedin
- 1
- 1