01-31-2014 06:27 AM - edited 01-31-2014 06:28 AM
Today I have another unusual task. I need to place some Control ( e.g. button or any other one ) over the Label (or anything that can display text) right after the last symbol of the text. I guess I can use AbsloluteLayout to set actual position of the control over the Label, but I'm not sure how to find this position.
The label can have multiple lines and text can have totally different length.
Can anyone help me with this?
Solved! Go to Solution.
01-31-2014 06:34 AM
01-31-2014 06:43 AM
Over the end of the text, right after last character. So if last line is shorter than the whole label, my button should be placed on this last line after the final word.
01-31-2014 06:48 AM
That's a tough one as even with a fixed width font if you are having a multiline label it's going to be hard to work out where the sentences will break.
Any chance you can change the design or is it fixed?
I say that because I think you will have to write your own custom control which although doable is a sizeable bit of work.
01-31-2014 07:00 AM - edited 01-31-2014 07:01 AM
Well, I've tried (not so hard actually) to create my own Control, but with no success yet.
And there's no way to change the design - my client wants a complete copy of his iOS/Android app and this feature is implemented there (unfortunately I can't have those sources).
Right now I have temporary solution with WebView and a simple HTML/CSS code, but since it's a list item I've got some troubles with the speed.
So I need to solve this problem of getting width/height of a text and lines...
01-31-2014 07:17 AM
Creating a custom control is not the hard part it's writing a custom control where you are responsible for placing the characters which would be fairly non-trivial.
Getting the width and height is not the problem, with a fixed width font you can work out where the last character is on a single line and calculate the x & y.
The problem starts when that text goes over one line at that point you can measure the height of the control but unless you know where the breaks appeared in the sentence I can't see how you would then know where the last word is you'd know the y but not the x.
01-31-2014 07:30 AM
It's always possible that I've missed something but I spent a lot of time reading up on everything to do with text for my app and I can't recall anything that would even remotely help you. I can't even think of a hacky way to do it.
You would also need to cope with the user changing the default font size. Something that can be easily locked out but not easily accommodated.
I think you are left with basically writing your own custom control Label.
Or cheating and accepting the button always on the bottom-right, after all how different will it look from iOS most of the time.
01-31-2014 08:35 AM
It will look pretty much different. That list is designed as for web page. At least problem easily solves with HTML and they have the same design in their website.
How do you think, is it possible to find a position of any predefined charachter? What if I'll put it after the text and will look for its position after the text is set. Would it help?
01-31-2014 08:57 AM