我的問題的區域如下:不考慮背景的計算項目
我有一個ImageView
與背景。背景是可繪製的,根據狀態繪製不同的圖像。
context_menu_button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Focused -->
<item android:drawable="@drawable/button_round_focused"
android:state_focused="true"/>
<!-- Pressed -->
<item android:drawable="@drawable/button_round_focused"
android:state_pressed="true"/>
<!-- Normal -->
<item android:drawable="@android:color/transparent"/>
</selector>
然後,我有一個star icon
這個context_menu_button
應用爲背景:
<ImageView
android:id="@+id/btnStar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/context_menu_button"
android:focusable="true"
android:src="@drawable/icon_star" />
圖像0其實是非常大的,因爲它是一個圖像具有非常微妙的漸變。在正常狀態下沒有圖像(透明色)。這是上面的XML的樣子(聚焦狀態):
這種背景的大小是造成我帶來些麻煩。繪製星形圖標時,會考慮背景以計算圖標星形的面積。所以,當我將兩個或更多的圖標對齊時,它們彼此相距很遠。
<ImageView
android:id="@+id/btnStar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/context_menu_button"
android:focusable="true"
android:src="@drawable/icon_star" />
<ImageView
android:id="@+id/btnShare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/context_menu_button"
android:focusable="true"
android:src="@drawable/icon_share" />
<ImageView
android:id="@+id/btnRate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/context_menu_button"
android:focusable="true"
android:src="@drawable/icon_rate" />
我的解決辦法是設置左切緣陰性,他們和我們一起關閉。
但是,這個方案引起了另一個問題。現在,項目重疊:現在
,例如,當我嘗試在項目份額單擊(中間按鈕),它實際上是第三個按鈕被點擊,因爲它們重疊。
我的理想解決方案是應用於ImageView
的背景沒有被考慮到,以計算它應用到的項目的面積。事情是這樣的:
換句話說,背景可能走出ImageView
的面積。
我認爲這可以解決問題,但我一直在閱讀文檔,我找不到與此相關的任何內容。任何其他的想法將不勝感激(雖然改變背景的大小是不可能的)。
感謝您的幫助。