我想找到视图在显示屏上的位置。
为了实现这个目标,我使用诸如
是否有其他方法可以查找视图的位置(即屏幕坐标)?
我的布局
为了实现这个目标,我使用诸如
view.getLeft()
,view.getBottom()
,view.getRight()
和view.getTop()
等方法。但不幸的是,所有这些方法都返回了0
。是否有其他方法可以查找视图的位置(即屏幕坐标)?
我的布局
main.xml
:<TextView android:id="@+id/tv1"
android:layout_width="200px"
android:layout_height="30px"
android:text="welcome to" />
<TextView android:id="@+id/tv2"
android:layout_width="200px"
android:layout_height="30px"
android:text=" Make Eit solution " />
我的类在 onCreate()
方法中有这样的代码:
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv1 = (TextView) findViewById(R.id.tv1);
tv2 = (TextView) findViewById(R.id.tv2);
System.out.println("tv4 width:"+tv2.getWidth());
System.out.println("tv4 height:"+tv2.getHeight());
System.out.println("Right:"+tv2.getRight());
System.out.println("Left:"+tv2.getLeft());
System.out.println("Top:"+tv2.getTop());
System.out.println("Bottom:"+tv2.getBottom());