0

I have an ImageView which contains an image of a Sudoku grid. I am creating a GridView which is containing all the numbers of the Sudoku grid. So it should completely overlay the ImageView. Here is the code:

   <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:layout_above="@+id/textView"
        android:layout_below="@+id/timer">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/imageView"
            android:layout_gravity="center"
            android:src="@drawable/sudoku_grid_2"
            android:scaleType="fitXY"/>

        <GridView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/sudoku_grid"
            android:layout_gravity="center"
            android:numColumns="9"
            android:verticalSpacing="10dp"
            android:horizontalSpacing="5dp"/>


</FrameLayout>

NOTE: The horizontal and vertical spacings been given in terms of dp.

Here is the code for creating GridView:

     public View getView(int position, View convertView, ViewGroup parent) {
            ImageView imageView = new ImageView(context);
            imageView.setImageResource(numbers.get(position));
            imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
            imageView.setLayoutParams(new GridView.LayoutParams(120, 120));
            //Some more lines
            return imageView;
}

The size of each Grid item is also given in terms of dps.

How can I make my app to be supported by screens having different sizes and densities?

Ojasva Jain
  • 81
  • 2
  • 7
  • Why don't you set borders to your gridview instead ? – alxscms Dec 21 '15 at 17:10
  • I didn't know about it as I am new to Android development. I will try it. Thanks. – Ojasva Jain Dec 21 '15 at 17:18
  • Check [this](http://android--code.blogspot.fr/2015/08/android-gridview-border-between-items.html) out, it might not be what you're just looking for, but it can work – alxscms Dec 21 '15 at 17:22
  • 1st for your idea..i would like refer you for and old question... http://stackoverflow.com/questions/14168734/how-to-set-a-fixed-number-of-rows-in-android-gridview...in tht you will know gridview is not aplicable for your sudoku.? – Anil Prajapati Dec 22 '15 at 04:56

0 Answers0