Android:按百分比排名?

时间:2013-06-10 17:06:39

标签: android layout relativelayout scaling percentage

我的设计师有一个UI设计,它有一个背景地图,上面有几个按钮,在整个地图上都是非线性的。目前,我将它们放在与地图一样大的RelativeLayout中,并在margin-left中使用margin-topdip等。

这项工作正常,但我还需要考虑屏幕非常小的用户,这会导致地图缩小。我的相对布局与它相关,但是边际值不是。

所以我想知道,我该怎么做?我更喜欢使用像

这样的百分比来布局这些按钮
left="30%"
top="50%"

Android中是否有任何可以实现这一目标的东西?否则,我必须为此提出一个自定义布局类。

视觉表示:(当然,它们实际上不在6行上,在x或y位置部分重叠)。它实际上是一个带有位置标记的建筑物的真实(抽象)地图,您可以将其按为按钮。

 -------------------------
 |    x              x   |
 |           x           |
 |                       |
 |      x                |
 |                 x     |
 |           x          x|
 -------------------------

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

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

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

Storing dimensions in xml file in Android