在图像中制作多个clickacble区域 [英] Make multiple clickacble areas in an image

查看:76
本文介绍了在图像中制作多个clickacble区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张图片,如果用户单击图片的不同部分,我想执行不同的操作.

I have an image, and I want to preform a different action if the user clicked on different parts of the image.

我是一个新的业余爱好者,所以我不了解我在研究中发现的所有内容. 我找到了几种解决方案,但我不太了解如何实现

I am kinda of new hobbyist, so I don't understand everything I find on my research. I have found a couple of solutions, but I don't quite understand how to implement any

  1. 屏蔽图像并获取像素图片下方的颜色,以了解已单击的区域

ImageMap

PS:

  • 图像像桌子一样呈网格状(如果有帮助的话)(绘制表格不是一种选择)
  • 我看到了其他两种解决方案,但我不理解它们,因此请不要将其标记为重复.我可以理解这些答案背后的想法,但是我无法实现它们.我不知道如何处理答案中提供的代码.

我成功制作了一些透明按钮并将它们放置在图像上,但是当在不同屏幕上进行测试时,按钮会从其相对位置移动. 我将对按钮方面的帮助有所帮助,或者说明了执行此操作的另一种方法.

I have Succeeded in making some transparent buttons and placing them on the image, but the buttons move from their relative positions when testing on different screens. I would appreciate a help with the buttons stuff, or explaining a different way to do this.

推荐答案

使用PercentRelativeLayout在图像上方添加按钮层 https://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html

Add layer of buttons over the image using PercentRelativeLayout https://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html

首先添加一个库:

dependencies {
    compile 'com.android.support:percent:25.3.1'
}

然后在您的布局文件中:

Then in your layout file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ImageView
        android:layout_width="100dp"
        android:layout_height="200dp"
        android:background="@android:color/black" />

    <android.support.percent.PercentRelativeLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="100dp"
        android:layout_height="200dp">

        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white"
            app:layout_heightPercent="50%"
            app:layout_marginLeftPercent="25%"
            app:layout_marginTopPercent="25%"
            app:layout_widthPercent="50%" />
    </android.support.percent.PercentRelativeLayout>

</RelativeLayout>

此按钮将在图像中心. 如果您想放置在其他地方,则可以使用像素计算位置并在预览中查看. 按钮应具有透明背景.

This button will be in center of image. If you want to place in somewhere else your can count your position using pixels and see it on the preview. Buttons should have transparent background.

这篇关于在图像中制作多个clickacble区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆