How to place transparent buttons over an image relatively?

痴心易碎 提交于 2019-12-23 02:54:24

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/4760284/how-to-place-transparent-buttons-over-an-image-relatively

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!