Introduction
In this article, we are going to learn about how to create a custom grid view in Xamarin Android
Step 1
In this article, we are going to learn about how to create a custom grid view in Xamarin Android
Step 1
Create your Xamarin Android solution in Visual Studio/Xamarin Studio
Step 2
Create a gridview in Main.axml
Step 3
Create a item class that holds name property and resource property

- public class Item
- {
- public string Name { get; set; }
- public int Resource { get; set; }
- }
Step 4
Create a custom image View that display the image in full view.
- public class SquareImageView : ImageView
- {
- public SquareImageView(Context context, IAttributeSet atrs) : base(context, atrs)
- {
- }
- public SquareImageView(Context context, IAttributeSet atrs, int defStyle) : base(context, atrs, defStyle)
- {
- }
- protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
- {
- base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
- SetMeasuredDimension(MeasuredWidth, MeasuredHeight);
- }
- }
Step 5
Now create a custom layout griditem.axml that fits into the grid view created in Main.axml

- <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <"your-namespace".SquareImageView
- android:id="@+id/picture"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:scaleType="centerCrop"/>
- <TextView
- android:id="@+id/text"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textSize="12dp"
- android:gravity="center"
- android:layout_gravity="bottom"
- android:textColor="@android:color/white"
- android:background="#55000000"/>
- </FrameLayout>



santhosh PSPosted May 15, 2018, 2:25 AM
Thanks Dude! Nice article. It will be helpful if you could share source code as well.
Techno (Dule)Posted Mar 16, 2018, 12:42 PM
It is a lot easier to post source code, since your steps are not quite ok; screenshots are not following code in frames, they are not in copy/paste-able, and you commented where to put code very badly.