在Android的显示(屏幕)寻找查看位置(位置) [英] Finding the View location (position) on display (screen) in android
问题描述
我想找到视图的显示屏幕上的位置。
要做到这一点,我使用的方法,如 view.getLeft()
, view.getBottom()
, view.getRight()
, view.getTop()
。但不幸的是,将返回所有这些方法 0
。结果
有没有找到视图的位置(即屏幕上的坐标)?
我的布局的main.xml
:
< TextView的机器人:ID =@ + ID / TV1
机器人:layout_width =200像素
机器人:layout_height =30像素
机器人:文字=欢迎/>< TextView的机器人:ID =@ + ID / TV2
机器人:layout_width =200像素
机器人:layout_height =30像素
机器人:文字=请EIT解决方案/>
和我的类有这的onCreate()
:
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);TV1 =(的TextView)findViewById(R.id.tv1);
TV2 =(的TextView)findViewById(R.id.tv2);的System.out.println(TV4宽度:+ tv2.getWidth());
的System.out.println(TV4高度:+ tv2.getHeight());
的System.out.println(右+ tv2.getRight());
的System.out.println(左+ tv2.getLeft());
的System.out.println(壮志:+ tv2.getTop());
的System.out.println(底部+ tv2.getBottom());
使用 getLeft()
, GetRight时()
,共达()
和 getBottom()
。该视图被实例化后,这些都可以使用。
I want to find the view's position on the display screen.
To do it, I use the methods such as view.getLeft()
,view.getBottom()
, view.getRight()
, view.getTop()
. But unfortunately, all these methods are returned 0
.
Is there any alternate way to find the view's positions (i.e coordinates on screen)?
My layout 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 " />
And my class has this in 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());
Use the getLeft()
, getRight()
, getTop()
, and getBottom()
. These can be used after the view is instantiated.
这篇关于在Android的显示(屏幕)寻找查看位置(位置)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!