2013-11-14 49 views
0

我正在創建一個鼓應用程序。一切正常。但鼓的圖像不是圓形的。我的意思是他們看起來像是圓圈,但當碰到它時,它周圍的整個正方形區域正在響應。圓角的圖像不工作

我在鼓圖像的佈局中使用imageviews。並且ontouchlistener在那imageviews

對於離

enter image description here

忽略黑色part..Consider我的鼓僅僅是圖像中的紅色部分。白色部分不可見,但當手指觸摸白色部分時,它會作出響應。

我曾嘗試在一些論壇中添加圓角背景。

roundbutton.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle"> 
<solid android:color="#eeffffff" /> 
<corners android:bottomRightRadius="8dip" 
    android:bottomLeftRadius="8dip" 
    android:topRightRadius="8dip" 
    android:topLeftRadius="8dip"/> 
</shape> 

將此添加到imageviews,但仍然沒有工作。請幫幫我。

+0

你爲什麼不使用Photoshop整齊地裁剪圖片爲圓視圖,使其.png格式,然後在您的應用程序使用此物品將顯示? – Coderji

+0

是的,我做到了。我有一個完美的圓圈。但不工作。 –

+0

即使顯示的圖像不是,按鈕也總是正方形。您將手動檢查TouchEvent是否在圓的半徑之外並在此情況下將其丟棄。 – Jave

回答

0

修改roundbutton.xml到選擇Android的指定項目:state_pressed = 「真」。當你點擊

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_pressed="false"> 
     <shape android:shape="rectangle"> 
      <solid android:color="#eeffffff"/> 
      <corners android:radius="8dp"/> 
     </shape>   
    </item> 

    <item android:state_pressed="true"> 
     <shape android:shape="rectangle"> 
      <solid android:color="#eeffff00"/> 
      <corners android:radius="8dp"/> 
     </shape> 
    </item> 
</selector> 
+0

你不明白我的問題..我不想要一個選擇器..我只想觸摸圓..不是圍繞它的方形。 –

+0

這是難以實現的。您必須重寫onTouchListner並計算觸摸位於imageview的半徑之內還是之外 – SathMK