[英]How to get the exact coordinate of a view in android?
我想创建一个应用程序,用户可以通过箭头链接两个文本视图; 例如,当用户在左侧的“文本”视图中单击,而在右侧的“文本”视图中单击时,应用程序应自动生成一行,我的问题是找到我尝试使用get Top()的两个视图的确切协调。但是,使用getLocationOnScreen();总是使箭头的位置不在正确的位置。
...
iv = (ImageView) findViewById(R.id.imageView1);
d = getWindowManager().getDefaultDisplay();
float dw = d.getWidth();
float dh = d.getHeight();
bit = Bitmap.createBitmap((int) dw, (int) dh, Bitmap.Config.ARGB_8888);
can = new Canvas(bit);
paint = new Paint();
paint.setColor(Color.BLACK);
iv.setImageBitmap(bit);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Button text = (Button)findViewById(R.id.button2);
can.drawLine(text.getLeft() + text.getWidth(), text.getTop() + (text.getHeight()/2), button.getLeft(), button.getTop() + (button.getWidth()/2), paint);
iv.invalidate();
}
}
)
;
}
}
您是否尝试过textView.getX(); 对于x坐标和textview.getY()对于y坐标...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.