简体   繁体   English

是否可以使每个屏幕尺寸的按钮和imageview对齐?

[英]Is it possible to keep buttons and imageview aligned for every screen size?

Possible Solution at the bottom of the description 说明底部的可能解决方案

I'm building an app where a have an image with several clickable spots. 我正在构建一个应用程序,其中有一个带有几个可点击位置的图像。 I'm using buttons over these clickable spots and then make them invisible, so it looks like you are clicking the image. 我在这些可点击的位置上使用了按钮,然后使它们不可见,因此看起来您正在单击图像。 I'm using a constraint layout and several guidelines positioned using percentage of the screen. 我正在使用约束布局,并使用屏幕百分比定位了一些准则。 I though that this way, different screen sizes would not impact the position of buttons and image, since i'm working with percentage and restrained buttons to these guidelines. 我采用这种方式,但是不同的屏幕尺寸不会影响按钮和图像的位置,因为我正在按照这些准则使用百分比和约束按钮。 Turns out that it actually does impact. 事实证明它确实有影响。

I'm adding a screenshot of how I would like for the buttons to look like and how they look after I change the screen size: 我添加了一个屏幕截图,说明我希望按钮的外观以及更改屏幕尺寸后的外观:

After screen resize: 屏幕调整大小后:

PS: not all buttons are positioned yet, because I stopped after noticing the problem. PS:并非所有按钮都已定位,因为注意到问题后我停了下来。

Possible Solution: 可能的解决方案:

I kept on trying to come up with a solution to this problem and i might have found one: 我一直在努力想出解决这个问题的方法,但我可能已经找到了一个:

Instead of buttons, i'm using imageviews for each part of the image (beams, pilars and slabs) and no image on the background. 而不是按钮,我在图像的每个部分(梁,支柱和平板)使用imageviews,而背景上没有图像。 This way, the plant is actually "drawn" by these imageviews and i have no problem with different screen sizes. 这样,实际上是由这些图像视图“绘制”了植物,并且对于不同的屏幕尺寸我也没有问题。 I'm still using a constraint layout and guidelines based on percentage. 我仍在使用基于百分比的约束布局和准则。

The problem of this solution is that it's a really boring and long process, but i'm still looking for a better method 该解决方案的问题在于这是一个非常无聊且漫长的过程,但我仍在寻找更好的方法

You can give a try to this great library https://github.com/intuit/sdp 您可以尝试一下这个很棒的库https://github.com/intuit/sdp

It actually provide a new scale unit which is sdp (scalable dp). 它实际上提供了一个新的标度单位,即sdp (可缩放dp)。

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

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