I need to create a canvas in which i have add two images as BITMAP and a TEXTVIEW at the bottom right with multiple line.
Here is my code which i have tried -
drawnBitmap = Bitmap.createBitmap(1000, 1500, Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(drawnBitmap);
canvas.drawColor(getResources().getColor(R.color.creamColor));
// JUST CHANGE TO DIFFERENT Bitmaps and coordinates .
canvas.drawBitmap(b, 0, 0, null);
canvas.drawBitmap(b2, 630, 250, null);
//for more images :
// canvas.drawBitmap(b3, 0, 0, null);
// canvas.drawBitmap(b4, 0, 0, null);
/*Draw text*/
//TextPaint paintText=new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
Paint paintText = new Paint(Paint.ANTI_ALIAS_FLAG);
paintText.setColor(Color.BLACK);
paintText.setTextAlign(Paint.Align.CENTER);
paintText.setTextSize(50);
Typeface tf;
tf = Typeface.createFromAsset(getAssets(), "HelveticaNeueLTStd-Lt.otf");
paintText.setTypeface(tf);
RelativeLayout layout = new RelativeLayout(this);
layout.setBackgroundColor(Color.GREEN);
layout.setDrawingCacheEnabled(true);
TextView textView = new TextView(this);
textView.setVisibility(View.VISIBLE);
textView.setText(INNERTEXT);
textView.setTextSize(30);
textView.setWidth(300);
textView.setTextColor(Color.BLACK);
textView.setTypeface(tf);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
layout.setLayoutParams(params);
textView.setGravity(Gravity.CENTER);
layout.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
layout.addView(textView);
layout.measure(canvas.getWidth(), canvas.getHeight());
layout.layout(0, 0, canvas.getWidth(), canvas.getHeight());
// To place the text view somewhere specific:
// canvas.translate(500, 750);
canvas.drawBitmap(layout.getDrawingCache(), 500, 750, null);
// layout.draw(canvas);
I have divided the canvas into 4 equal parts, but the textview inside the 4. part is not centered.