我有一些区域的图像。我想对特定区域的点击作出反应,但我无法将此图像剪切成单独的图像。你可以看到下面的例子。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