2010-08-09 62 views
2

可以通過分享有關如何在android中的圖像頂部繪製小矩形的知識來幫助我。 我有main.xml,並有一些小部件。在頂部,有一個圖像,我想在該圖像上繪製一個矩形,並在應用程序運行時同時顯示。在xml中在圖像上繪製視圖

這裏是我的xml文件看起來像:

<?xml version="1.0" encoding="utf-8"?> 
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_margin="5px" android:padding="20px"> 
    <ImageView 
    android:id="@+id/myImageView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/sinewave"/> 
    <TableRow> 


    </TableRow> 

    <TableRow>  
      <TextView android:text="00:00" 
       android:id="@+id/TextView02" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:paddingBottom="30dip" 

       android:gravity="center"> 
      </TextView>  
    </TableRow> 
    <TableRow android:gravity="center"> 

      <Button android:text="Start" 
        android:id="@+id/btnStart" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:padding="20px" 
        > 
      </Button> 



      <Button android:text="Stop" 
        android:id="@+id/btnStop" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:padding="20px" 
        > 
      </Button> 

    </TableRow> 
    <TableRow> 
      <TextView android:text="" 
       android:id="@+id/TextView01" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:paddingLeft="5px" 
android:paddingRight="5px" 
android:paddingTop="10px" 
android:paddingBottom="10px" 

       > 
      </TextView> 

    </TableRow> 
    <TableRow> 
      <Button android:text="Mute Phone" 
        android:id="@+id/Button01" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:gravity="center" 
        android:paddingBottom="10dip" 
       > 
      </Button> 
    </TableRow> 
    <TableRow> 
      <Button 
       android:text="Settings" 
       android:id ="@+id/btnClick" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:paddingTop="30dip" 
      /> 
    </TableRow> 

</TableLayout> 
+0

http://stackoverflow.com/questions/ 3569412 /定製-複選框偏好 – 2010-08-25 21:07:32

回答

3

不要使用標準的ImageView爲。創建您自己的類擴展視圖。然後重寫draw()方法。在那裏你可以顯示圖像,並做所有你想要的東西,包括繪製矩形。

0

您可以使用ImageView ...我其實已經在我的一個應用程序中完成了這項工作。然後你就可以覆蓋的OnDraw()方法,它通過在你可以用它來畫上一個畫布...

我用這個作爲參考: Draw onto an ImageView