I have a custom view and I simply wish to access the xml layout value of layout_height
.
I am presently getting that information and storing it during onMeasure, but that only happens when the view is first painted. My view is an XY plot and it needs to know its height as early as possible so it can start performing calculations.
The view is on the fourth page of a viewFlipper layout, so the user may not flip to it for a while, but when they do flip to it, I would like the view to already contain data, which requires that I have the height to make the calculations.
Thanks!!!
The answers which are written to this question do not completely cover the issue. Actually, they are completing each other. To sum up the answer, first we should check the
getAttributeValue
returning value, then if thelayout_height
defined as dimension values, retrieve it usinggetDimensionPixelSize
:You can use this:
that work :)... you need to change "android" for "http://schemas.android.com/apk/res/android"
From public View(Context context, AttributeSet attrs) constructor docs:
So to achieve what you need, provide a constructor to your custom view that takes Attributes as a parameter, i.e.: