2016-04-01 32 views
0

我正在学习Android中的坐标系。了解Android中的矩形

我想知道为什么在右侧的X坐标值中出现负号。

矩形的总宽度应为100px。(请参阅图像ID'图像')。

矩形的结果是:

Rect(20, 95 - 120, 195) 

XML布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_marginLeft="10px" 
    android:layout_marginTop="10px" 
    android:layout_height="match_parent"> 

<LinearLayout 
    android:orientation="vertical" 
    android:layout_marginLeft="10px" 
     android:layout_marginTop="10px" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 


    <ImageView 
     android:id="@+id/image" 
     android:src="@drawable/ic_launcher" 
     android:layout_width="100px" 
     android:layout_height="100px" 
     /> 

    </LinearLayout> 
    <ImageView 
     android:id="@+id/image2" 
     android:src="@drawable/ic_launcher" 
     android:layout_width="100px" 
     android:layout_height="100px" 
     /> 

</LinearLayout> 
+0

显示一些代码,你如何得到这个'Rect'值? – Bryan

回答

0

我找到了答案。它实际上是(x1,y1),(x2,y2)。连字符只是一个分隔符。

+0

连字符不是分隔符,它是一个减法,因此构造函数不需要3个参数就是语法错误。 –

+0

我对imageview使用了'getglobalvisiblerect()'方法并传递了一个Rect变量。带连字符的输出是我得到的矩形的输出。 – Ayush