在Android的显示器(屏)寻找查看位置(位置) [英] Finding the View location(position) on display(screen) in android

查看:149
本文介绍了在Android的显示器(屏)寻找查看位置(位置)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要查找的显示屏幕上的视图位置。

要做到我所使用的方法,如 view.getLeft() view.getBottom() view.getRight() view.getTop()。但不幸的是所有这些方法都返回了0(零)。是否有任何替代找到视图位置,即坐标?

main.xml中我的code段

  **< TextView的机器人:ID =@ + ID / TV1
        机器人:layout_width =200px的
        机器人:layout_height =30像素
        机器人:文本=欢迎

    />
    < TextView的机器人:ID =@ + ID / TV2
        机器人:layout_width =200px的
        机器人: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 position on the display screen.

To do the I use the methods such as view.getLeft() ,view.getBottom() , view.getRight() , view.getTop(). But unfortunately all these methods are returned the "0"(Zero). Is there any alternate to find the view positions ,i.e coordinates?

My code snippet in 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 "
    />**

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆