gpt4 book ai didi

android - getLocationOnScreen 返回错误值

转载 作者:行者123 更新时间:2023-11-29 17:43:53 27 4
gpt4 key购买 nike

我将以下 3 个包裹在 RelativeLayout 中(忽略 visibility="gone")。

<ImageView
android:id="@+id/img1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_marginLeft="10dip"
android:visibility="gone"/>

<ImageView
android:id="@+id/img2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:visibility="gone"/>

<ImageView
android:id="@+id/img3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_marginLeft="60dip"
android:layout_alignParentBottom="true"
android:layout_marginBottom="100dip"
android:visibility="gone"/>

当我调用 view.getLocationOnScreen(pos);

我为 pos[0] 返回 0,为 pos[1] 返回 219,即使它们都不在那些 (x,y) 坐标上。令人费解的是,每个 ImageView 都给我相同的值,尤其是考虑到它们位于不同的位置。为什么会这样?

最佳答案

在您的布局中,所有 ImageView 都处于“消失”状态。所以 getLocationOnScreen() 方法返回左上角位置。

如果您想获得 View 的确切位置,请根据您的要求将它们的可见性更改为“不可见”或“可见”。

关于android - getLocationOnScreen 返回错误值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27752955/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com