2016-04-01 31 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