我想要求设备内部的 imageview 位置。但每次它都会返回 0。我用这个代码来做到这一点:
tv1=(TextView)findViewById(R.id.textView1);
tv1.setText("Accessing the position of the widget in device");
Rect rectf = new Rect();
tv1.getLocalVisibleRect(rectf);
System.out.println("top" + rectf.top );
System.out.println("Left:" + rectf.left);
System.out.println("Right:" + rectf.right);
System.out.println("Bottom:" + rectf.bottom);
输出 :
10-12 05:42:55.101: I/System.out(31578): top:0
10-12 05:42:55.101: I/System.out(31578): Left:0
10-12 05:42:55.101: I/System.out(31578): Right:0
10-12 05:42:55.101: I/System.out(31578): Bottom:0