1

First of all, related questions to my topic:

How do I access layout_height from within my custom view?

How do you get "android:" tag values in a Custom View.

So I have the result in a String which is ok, but the question is: is there a way to somehow automatically parse the String result that I get back from attrs.getAttributeValue() or is there a solution to get it somehow in an already parsed format ( = get the value in pixels)? Like when you call getDimensionPixelSize().

Because the returned String can have values like ?2130772036 (reference), -2 (wrap_content), 122.0dip (or in the worst case 122px, 122mm, etc...).

And I don't want to add layout_height to my custom attrs.xml if not necessary.

Community
  • 1
  • 1
ktamas
  • 313
  • 3
  • 15
  • 2
    are you aware of `onMeasure` method? – pskink Nov 15 '16 at 11:10
  • I am, but the thing is that I want to have the height information before `onMeasure` is called. I have a custom function and when it is called, the layout is not rendered yet, but I already need the height to manipulate other views based on the height of this one. I might go with `getMeasuredHeight()` solution, but still, it would be nice to get the height nicely from the attributes. – ktamas Nov 15 '16 at 11:53
  • Well, as an extra piece of information: my view is `GONE` when I call my custom function on it, so `onMeasure` is not yet called at that time. – ktamas Nov 15 '16 at 11:57
  • if you want size in pixels this is the correct place, otherwise you will get things like -1 / -2 (for dims like match_parent / wrap_content) – pskink Nov 15 '16 at 11:59
  • Probably I have to go with this one: http://stackoverflow.com/a/10134260/7138729 – ktamas Nov 15 '16 at 12:55
  • this is called **after** `onMeasure` / `onLayout` got called – pskink Nov 15 '16 at 13:00
  • Well, the point is to me to get the height **before displaying** it and to be able to measure it when I want it, not when user calls display. I just thought that at the time of `onMeasure` or `onLayout` there is no way back and if I call `setVisibility(GONE)` on these functions, then the view might blink for a moment and I definitely don't want that. However if the view does not blink and I can control when to measure height, than it is fine. Sorry for not being precise. – ktamas Nov 15 '16 at 13:13
  • so maybe you will find the direct call to `View#measure` helpful? – pskink Nov 15 '16 at 13:18

0 Answers0