There are two main ways that I can think of you could use. Like you said, you could use a Button
/TextView
and set the background as the hexagon resource. As you said though, that requires inflating that view every time. The other way would be to use a Canvas
and draw the number directly on the image, then put the image into an ImageView
or other similar view. To draw on the image:
int fontSize = 200; //set your font size
Bitmap baseImage = BitmapFactory.decodeResource(this.getResources(), R.drawable.hexagon); //load the hexagon image
Bitmap image = baseImage.copy(Bitmap.Config.ARGB_8888, true); //create mutable bitmap for canvas. see: http://stackoverflow.com/a/13119762/1896516
//the "paint" to use when drawing the text
Paint paint = new Paint(); //see here for all paint options: https://developer.android.com/reference/android/graphics/Paint.html
paint.setTextSize(fontSize); //sets your desired font size
paint.setColor(Color.BLACK); //set the desired color of the text
paint.setTextAlign(Paint.Align.CENTER); //set the alignment of the text
Canvas canvas = new Canvas(image); //create a canvas from the bitmap
canvas.drawText("#", image.getWidth()/2, image.getHeight()/2 + fontSize/4, paint); //draw the number onto the hexagon
ImageView iv = (ImageView) findViewById(R.id.iv);
iv.setImageBitmap(image);
You may need to play with the text positioning depending on if your image has borders, etc. In addition, note that I haven't really tested these two against eachother for performance, so I'm not sure which one will be the most effecient way in the end. That said, the first way is likely easier to do as it will take care of positioning by itself. Hope this helps!