android 对话框的父view是谁,android – 在对话框中获取相对于其父级的视图位置
我想要做的是,從按鈕邊緣到屏幕上的一點(diǎn)畫一條線……
我正在使用一個(gè)對話框片段…我嘗試的所有函數(shù)總是返回0點(diǎn)…
我試過以下:
@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)繪制一條線……
如何獲得屏幕上按鈕的位置或相對于父視圖的優(yōu)先級?我認(rèn)為,他們的布局尚未完成,所以我必須稍后在某處畫出我的線條,但是時(shí)間和地點(diǎn)?
總結(jié)
以上是生活随笔為你收集整理的android 对话框的父view是谁,android – 在对话框中获取相对于其父级的视图位置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 项响琴C语言书籍在线浏览,电子琴 c语言
- 下一篇: linux vnc检查,检查Ubuntu