欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

android 对话框的父view是谁,android – 在对话框中获取相对于其父级的视图位置

发布时间:2025/3/11 编程问答 51 豆豆
生活随笔 收集整理的这篇文章主要介绍了 android 对话框的父view是谁,android – 在对话框中获取相对于其父级的视图位置 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

我想要做的是,从按钮边缘到屏幕上的一点画一条线……

我正在使用一个对话框片段…我尝试的所有函数总是返回0点…

我试过以下:

@Override

protected Dialog createDialog(Bundle savedInstanceState, FragmentActivity activity)

{

Dialog d = builder.create();

View v = LayoutInflater.from(activity).inflate(R.layout.dialog, null);

builder.setView(v);

// custom view by my which draws simple lines between points...

LineDrawView ldv = new LineDrawView(getActivity());

ldv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

((RelativeLayout)v).addView(ldv);

Dialog d = builder.create();

button = ((Button) v.findViewById(R.id.button));

int[] pos = new int[2];

button.getLocationInWindow(pos);

// tried following ways, all always return p(0, 0)

// button.getLocationInWindow(pos);

// Debugger.d("x: " + pos[0] + ", y: " + pos[1], "POS");

// button.getLocationOnScreen(pos);

// Debugger.d("x: " + pos[0] + ", y: " + pos[1], "POS");

// float x = button.getLeft();

// float y = button.getTop();

// Debugger.d("x: " + x + ", y: " + y, "POS");

ldv.addLine(new Point(pos[0], pos[1]), new Point(pos[0] + 30, pos[1]), Color.RED);

ldv.invalidate();

return d;

}

并且它总是从p(0,0)到p(0,30)绘制一条线……

如何获得屏幕上按钮的位置或相对于父视图的优先级?我认为,他们的布局尚未完成,所以我必须稍后在某处画出我的线条,但是时间和地点?

总结

以上是生活随笔为你收集整理的android 对话框的父view是谁,android – 在对话框中获取相对于其父级的视图位置的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。