简体   繁体   English

Android布局组织,用于对自定义形状的按钮进行分组

[英]Android layout organisation for grouping custom shaped buttons

I am trying to group the buttons in android so that it appear like in the image below. 我正在尝试在android中对按钮进行分组,以使其如下图所示。 I tried doing it using floating technique but I was not successful. 我尝试使用浮动技术进行操作,但未成功。 I was hoping that floating it top left and right may solve my problem but it doesn't seem to be working. 我希望将其左右浮动可以解决我的问题,但似乎没有用。

android按钮组

I am getting the result where all the buttons are stacked on top of each other or they are horizontally places one after the other. 我得到的结果是所有按钮都堆叠在一起,或者它们在水平方向上一个接一个地放置。

I have three buttons above as a separate image (png) files. 我上面有三个按钮,它们是一个单独的图像(png)文件。 I am trying to achive this using imageview which will be assigned a touchListener to act as a button. 我正在尝试使用imageview实现这一点,它将被分配一个touchListener充当按钮。

Any help would be great. 任何帮助都会很棒。

extend View class and draw your images like the image you have put here. 扩展View类并绘制图像,就像放置在此处的图像一样。 After that when a click occurs check coordinates to decide which colored button clicked. 之后,当发生单击时,请检查坐标以确定单击了哪个彩色按钮。

I used a technique from this blog. 我使用了该博客中的一种技术。

https://blahti.wordpress.com/2012/06/26/images-with-clickable-areas/ https://blahti.wordpress.com/2012/06/26/images-with-clickable-areas/

Basically, All you do is use two images. 基本上,您要做的就是使用两个图像。 Second image with hotspots goes on top of the main image (in this case above hexagon image) and then when you click, a function is called to find out what colour was clicked and depending on that you can call your action. 带有热点的第二个图像位于主图像的顶部(在本例中为六边形图像上方),然后单击时,将调用一个函数来找出单击了什么颜色,并根据此颜色来调用操作。

Hotspot image needs to be of same size as original image and the hotspots needs to be standard colorrs ie blue, red, yellow, etc to make it easy to determine which colour was clicked. 热点图像的大小必须与原始图像大小相同,并且热点必须是标准的着色器(例如蓝色,红色,黄色等),以便于确定单击哪种颜色。

Works nicely with the image above and works quite accurately too. 与上面的图像配合良好,并且也非常准确。

Other option is to use coordinates but I haven't had much time to look into this technique. 另一种选择是使用坐标,但是我没有太多时间研究这项技术。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM