gpt4 book ai didi

android - getLocationOnScreen() 返回零

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:01:06 26 4
gpt4 key购买 nike

我正在使用以下代码获取按钮的位置,但它总是返回零。为什么会这样

    Button b=(Button) findViewById(R.id.button2);
final int[] x=new int[2];
b.getLocationOnScreen(x);

我相信这里有人可以帮助我

最佳答案

试试这个..

Button b; 

在全局变量中

然后 onCreate()

b=(Button) findViewById(R.id.button2);

onCreate(); 之后

@Override
public void onWindowFocusChanged (boolean hasFocus) {
final int[] x=new int[2];
b.getLocationOnScreen(x);
}

关于android - getLocationOnScreen() 返回零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19582513/

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