我在 android 中创建了一个画布,里面有多个位图图像。我不想让这些图像可以点击。
到目前为止,我已经尝试过以下事情..
我试图在图像视图中添加位图,因为 imageview 有一个 setOnClickListner 但我认为 ImageView 不能添加到 Canvas 中,所以我放弃了这个想法。因为即使是 Bitmap 本身也没有点击事件。
我在 android 中创建了一个画布,里面有多个位图图像。我不想让这些图像可以点击。
到目前为止,我已经尝试过以下事情..
我试图在图像视图中添加位图,因为 imageview 有一个 setOnClickListner 但我认为 ImageView 不能添加到 Canvas 中,所以我放弃了这个想法。因为即使是 Bitmap 本身也没有点击事件。
If you want to use Canvas, keep in mind that it is a low level drawing mechanism.
Therefore, you need to implement the click logic yourself.
You also have to keep the coordinates of all images and the corresponding onClickListeners somewhere in memory.
Other solution:
Use a Layout, possibly a RelativeLayout, in which you add the ImageViews as children.
我相信你要求这样的东西:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<ImageView
android:id="@+id/clickable_image"
android:src="@drawable/ic_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="true"
/>
</LinearLayout>
现在您有了自己的背景“将整个视图设置为墙纸”,然后您就有了可点击的图像。在您的代码中,您实现 onClickListener 并将其附加到您的 ImageView 中,它将执行您想要执行的任何操作。