1

I have a UI Design from my designer, and it exists of a background map with several buttons on it, positioned non-linear all over the map. Currently I position them in a RelativeLayout that is as large as the map, and use margin-left and margin-top etc in dip.

This works ok, but I also need to account for users with very small screens, that cause the map to scale down. My relative layout scales with it, but the margin values ofcourse not.

So I am wondering, how should I do this? I would prefer to layout these buttons using percentages like

left="30%"
top="50%"

Is there anything in Android that makes such a thing possible? Otherwise I have to come up with a custom layout class for that.

Visual Representation: (Ofcourse they don't actually are on 6 lines, and partially overlap in x or y position). It's actually a real (abstract) map of a building with location markers that you can press as buttons.

 -------------------------
 |    x              x   |
 |           x           |
 |                       |
 |      x                |
 |                 x     |
 |           x          x|
 -------------------------
4

2 回答 2

1

这是一种不需要自定义 ViewGroup 的复杂方法。假设您想要一个按钮在左侧 30%,顶部 40%

FrameLayout 
   View with background, match parent
   LinearLayout orientation=horizontal, match parent 
     View layout_width=0dp, layout_weight=30, height=match_parent
     LinearLayout orientation=vertical, width=0dp, weight=70, hieght=match
       View layout_height=0dp, layout_weight=40, width=match_parent
       FrameLayout layout_height=0dp, layout_weight=60
         Button
于 2013-06-10T18:16:20.243 回答
0

我使用Dimension放置在相关布局存储桶中的资源文件,因此我可以根据设备大小更改边距/填充/大小。

http://developer.android.com/guide/topics/resources/more-resources.html#Dimension

在 Android 中将尺寸存储在 xml 文件中

于 2013-06-10T17:10:09.483 回答