Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android GridLayout Border

Tags:

java

android

I am working on a Tic-Tac-Toe.

However, i want to add a border to my GridLayout(Board)

Here is the following code of my gridLayout

<android.support.v7.widget.GridLayout
            android:id="@+id/boardGrid"
            app:columnCount="3"
            app:rowCount="3"
            app:alignmentMode="alignBounds"
            app:layout_widthPercent="100%"
            app:layout_aspectRatio="100%"
            android:background="@drawable/burledwood"
            android:layout_centerVertical="true">

Any help is greatly appreciated.

like image 782
Rohit Kumar Avatar asked Sep 01 '25 22:09

Rohit Kumar


1 Answers

Create A border.xml file:-

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item>
    <shape android:shape="rectangle">
      <solid android:color="#00fb9a"/>
      <stroke
        android:color="#5d05ff"
        android:width="3dp"/>
     </shape>
 </item>
</selector>

Apply that background file as background drawable in GridLayout

<android.support.v7.widget.GridLayout
            android:id="@+id/boardGrid"
            app:columnCount="3"
            app:rowCount="3"
            app:alignmentMode="alignBounds"
            app:layout_widthPercent="100%"
            app:layout_aspectRatio="100%"
            android:background="@drawable/border"
            android:layout_centerVertical="true">
like image 130
Sandeep Londhe Avatar answered Sep 04 '25 22:09

Sandeep Londhe