如何在图像上相对放置透明按钮?

发布于 2024-10-13 09:25:56 字数 550 浏览 7 评论 0原文

我正在Android中寻找一种方法,如何在(背景)图像上放置一些透明按钮,这样我就可以很好地控制按钮的位置,并且如果屏幕大得多,它们也会保持原样。

正如你可以想象的那样,图像还包含按钮艺术...

最好的事情是如果我可以使用百分比来定位按钮,但遗憾的是这在 Android 中是不可能的。

这是我当前的代码基础:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/art_main_background" >

作为替代方案,我也可以提取按钮艺术并将它们放置在图像上,但这会导致同样的问题,如果按钮不在 ' 中,我如何控制位置线性的顺序,即相当随机。

I am looking for a way in Android how to place some transparent buttons over a (background) image so I have good control to position the buttons and they stay were they meant to be also if the screen is much larger.

As you can imagine the image contains also the button art...

The best thing would be if I could position the buttons by using percentage, but sadly this is not possible in Android.

This is my current base of the code:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/art_main_background" >

As an alternative, I could also extract the button art and place them over the image, but this would lead to the same problem, how can I control the position if the buttons are not in a 'linear' kind of order, i.e. rather random.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

饮惑 2024-10-20 09:25:56

您绝对应该将按钮艺术制作为单独的部分,然后将它们作为 ImageButtons 放入。您可以使用 FrameLayout 将它们堆叠在图像顶部(实际上,如果将其设置为背景图像,您甚至不需要 FrameLayout),但我认为如果我理解正确的话,您会遇到更多问题。

您是否试图将单个图像作为控件,并将按钮映射到特定位置?考虑到屏幕分辨率和尺寸的多种变化,这在 Android 上是一个坏主意。考虑重新考虑您的布局,使其更加灵活。如果确实需要绝对定位,则可以使用 FrameLayout,只需指定左边距和上边距来定位它们,但请记住,可能完全适合一种分辨率的内容不一定适合另一种分辨率。

如果您可以发布您的想法示例,我们也许可以为您提供一些想法。

You should definitely make the button art separate pieces, and then place them in as ImageButtons. You can use a FrameLayout to stack them on top of the image (actually, if it's set as a background image, you shouldn't even need the FrameLayout) but I think you'll have more problems than that if I understand you correctly.

Are you trying to make a single image as your controls, and just map buttons to specific positions? Considering the number of variations in screen resolutions and sizes, this is just a bad idea on Android. Consider rethinking your layout to be a bit more flexible. If you do need absolute positioning, you can use a FrameLayout, and just specify left and top margins to position them, but keep in mind what might fit perfectly on one resolution won't necessarily fit into another properly.

If you can post a sample of what you've got in mind, we might be able to give you some ideas.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文