开发者

Can't get layout info when creating activity

开发者 https://www.devze.com 2023-01-08 23:14 出处:网络
I have this element in my layout XML: <FrameLayout android:id=\"@+id/FrameLayout01\" android:layout_width=\"320sp\" android:layout_hei开发者_运维知识库ght=\"380sp\"

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消