0

I was wondering how to achieve this. Is it like you instantiate a textView and let the user position it and set properties and then when the user hit the save button you take the property from the textView and make a paint object an add it to bitmap image? (if yes how do you get and set the position because the image that user sees is normally scaled down so it fit on the screen)

or is it like you make a new bitmap combining TextPaint and DynamicLayout like this (i dont know how to get width and height of my text because it will change based on text size, font, text length, etc...)

I'm a beginner and this would be my first app and also new to Java.

Amir Heshmati
  • 550
  • 1
  • 8
  • 19
  • i asked [this](http://stackoverflow.com/questions/36329802/positioning-a-text-on-an-image-based-on-a-textviews-position) but got no answer.. – Amir Heshmati Mar 31 '16 at 15:40
  • This is, essentially, a three part question. 1, how do you make a view that a user can move. 2, how do you get TextView attributes at runtime. 3, how do you draw a custom bitmap. What have you tried? – zgc7009 Mar 31 '16 at 15:47
  • I've written a class that holds the properties, there is a method on touch that i can overload to get the touch position and i guess i will assign that to textView's position and i would draw using a canvas .. but can't get the position write and i have tried [this](http://stackoverflow.com/questions/36329802/positioning-a-text-on-an-image-based-on-a-textviews-position) @zgc7009 – Amir Heshmati Mar 31 '16 at 16:07
  • Gotcha, so you actually have made a good bit of progress. I think the issue is in your understanding of Android's scaling mechanisms. You are using `paint.setTextSize(20 * scale);` under the logic that `i also set the textView's text size to 20`. Are you using scale independent pixels (sp), because 20px != 20sp. This http://stackoverflow.com/questions/6263250/convert-pixels-to-sp is the opposite conversion, but a similar idea. – zgc7009 Mar 31 '16 at 16:15
  • i have tried dp and pixel and got nowhere is sp diffrent? the main issue is position of the text. size would have a lesser priority. – Amir Heshmati Mar 31 '16 at 16:20
  • the closest i got to the position was the code I've mentioned – Amir Heshmati Mar 31 '16 at 16:23

1 Answers1

0

You would want to use canvas or Surface view. You would use bitmap to draw the image and then you canvas.paintText(...) to 'draw' the text with a Paint() data type. Use MotionEvent to follow the User's input. I'm not certain on how to save the canvas but I've heard of it being done fairly easily. You can use this site for learning the basics of canvas, paint, bitmap, Motion Events, and more. http://gamecodeschool.com/android/coding-a-breakout-game-for-android/

I can't provide specific examples with out code. Hope this Helps!

baron159
  • 32
  • 8
  • It should be noted that the link I supplied walks you through building a basic game engine. That part of that can be skipped you would want to focus more on the draw() methods in the project – baron159 Mar 31 '16 at 16:06
  • I have tried using Canvas.paintText here but the position dosent get scaled properly.. the problem is if i draw the text on the bitmap using canvas it won't be possible to move it and if i put it in a different View then i cant find the exact location on the actual bitmap because the image get scaled down so it fit on the screen and the margins that i assign to the view and the position on the canvas have different scale so the text doesn't end up at the right position. – Amir Heshmati Mar 31 '16 at 16:26
  • You can scale the Text to any size with paint.setTextSize(...). To move it around the canvas you would want to create a 'invisible' rectangle around the text so you can compare if the motion event occurred within the rectangle. You will need an update method for moving the text around because it will be 'redrawn' every frame. – baron159 Mar 31 '16 at 16:44
  • You mean i should reload the image and redraw the text again and again for every pixel that the text get moved? that doesn't sound like it's going to be very smooth. check out the app [phonto](https://play.google.com/store/apps/details?id=com.youthhr.phonto&hl=en) that's what i want to achieve... – Amir Heshmati Mar 31 '16 at 17:05
  • It is smooth thanks to thread, you'd be doing a lot of calculations though for resizing. So your update method could be relatively thick. I still believe canvas is the route you want to go with painting the text to canvas. You'd have to play around with different approaches to the canvas and updates but making a TextView extremely limits your capabilities. Or at least you'd have to do a lot more work to something that's given to you in combinations of Canvas, Paint, Surface View, and Motion Event. – baron159 Mar 31 '16 at 17:38
  • I did what you said redrawing it for every pixel and i didn't even had to use another thread and it runs really smooth. Thanks – Amir Heshmati Jun 29 '16 at 10:12