gpt4 book ai didi

android - 如何获得按钮在屏幕上的左右角位置?

转载 作者:行者123 更新时间:2023-11-29 23:47:33 24 4
gpt4 key购买 nike

我正在尝试获取 View 位置(右上角位置和左下角位置)并在 View 的右侧或左侧显示自定义对话框,但我没有获得 View 的确切位置。这是我的代码

    int x=view.getLeft()+  (view.getHeight()*4);
int y= view.getBottom()+(view.getWidth()*2);
showDialog(x,y,Gravity.TOP,Gravity.LEFT);`

public void showDialog(int x, int y,int gravity_y,int gravity_x){
final Dialog dialog = new Dialog(this, R.style.ActivityDialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.WHITE));
dialog.setContentView(R.layout.cofirm_sell);
dialog.setCanceledOnTouchOutside(false);
WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
dialog.getWindow().getAttributes().windowAnimations=R.style.DialogTheme;
wmlp.gravity = gravity_y | gravity_x;
wmlp.x = x;
wmlp.y = y;
ImageButton close=(ImageButton)dialog.findViewById(R.id.close);
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();

我要这个

enter image description here

最佳答案

检查这个:

    int[] outLocation = new int[2];
view.getLocationOnScreen(outLocation);
Rect rect = new Rect(
outLocation[0],
outLocation[1],
outLocation[0] + view.getWidth(),
outLocation[1] + view.getHeight());
//right upper corner rect.right,rect.top
//left bottom corner rect.left,rect.bottom

关于android - 如何获得按钮在屏幕上的左右角位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51185698/

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