Skip to content Skip to sidebar Skip to footer

Android: Position By Percentage?

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 RelativeLa

Solution 1:

Here is a complicated way that does not require a custom ViewGroup. Suppose you want a button at left 30%, top 40%

FrameLayout 
   Viewwith 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=matchView layout_height=0dp, layout_weight=40, width=match_parent
       FrameLayout layout_height=0dp, layout_weight=60
         Button

Solution 2:

I use Dimension resource files put in the relevant layout- buckets so I can change margins/paddings/sizes depending on device size.

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

(Storing dimensions in xml file in Android)

Post a Comment for "Android: Position By Percentage?"