I have this element in my layout XML:
<FrameLayout android:id="@+id/FrameLayout01"
android:layout_width="320sp" android:layout_hei开发者_运维知识库ght="380sp"
android:layout_gravity="center" android:background="#99CC33">
</FrameLayout>
And I want to get its position on the screen with getTop()
, getBottom()
,... but I want to do it only once.
I was trying to do it on the onCreate(), but those methods return all 0 as response.
Any tips?
The problem is that the screen isn't created before the onCreate. For example I used to try and get the screen height and width in the onCreate but it doesn't work because it's not set up yet. To solve the problem I used a custom View and overrode the function onSizeChanged.
精彩评论