表示画面上のビューの位置を見つけたい。
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());