我有一些區域的圖像。我想對特定區域的點擊作出反應,但我無法將此圖像剪切成單獨的圖像。你可以看到下面的例子。Android - 如何佈局圖像中的按鈕?
,圓點是我的領域。紅色矩形是我的透明按鈕。你將如何在XML中實現這一點?我想確保活動按鈕將始終覆蓋背景圖像中的相同區域。
我試圖做到這一點使用的FrameLayout:
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:src="@drawable/_podklad" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:layout_gravity="right|bottom"
android:contentDescription="prawy_tyl"
android:layout_marginRight="45dp"
android:layout_marginBottom="40dp"
android:layout_width="65dp"
android:layout_height="75dp"
android:background="@null"
android:src="@null"/>
<ImageButton
android:contentDescription="lewe_kolo_przod"
android:layout_marginLeft="30dp"
android:layout_marginTop="38dp"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@null"
android:src="@null"/>
<ImageButton
android:layout_gravity="bottom"
android:contentDescription="lewe_kolo_tyl"
android:layout_marginLeft="28dp"
android:layout_marginBottom="75dp"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@null"
android:src="@null"/>
<ImageButton
android:layout_gravity="right"
android:contentDescription="prawe_kolo_przod"
android:layout_marginRight="28dp"
android:layout_marginTop="40dp"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@null"
android:src="@null"/>
<ImageButton
android:layout_gravity="right|bottom"
android:contentDescription="prawe_kolo_tyl"
android:layout_marginRight="25dp"
android:layout_marginBottom="75dp"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@null"
android:src="@null"/>
</RelativeLayout></FrameLayout>
正如你可以看到我試圖指定的按鈕固定的寬度,高度和利潤,但在Android的工作室,它的工作以及在Nexus 4預覽,但在像Nexus 9這樣的大屏幕上,這些按鈕放錯了位置。
我等待你的想法。
問候。
我已經實現它使用'onTouchListener',如你所說:)現在我不需要擔心按鈕錯位。謝謝你的啓發! :) – 2015-03-03 10:27:24
不客氣:) – 2015-03-03 11:11:10