I'm trying to work out if it's possible to use percentage positions/sizes when creating a layout. What I want is something like this...
^
|
|
| 68%
|
|
v
Gallery (height equivalent of 16% total screen size)
^
| 16%
v
I'm testing on a device which in landscape has a display of 800x480 actual pixels and I'm currently forcing it with the following...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Gallery
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="80px"
android:layout_marginTop ="320px"
/>
</RelativeLayout>
Obviously I don't want to hard-code fixed px
units but I can't use 68%
or 0.68
for layout_marginTop
(for example). I've looked at dp
units but I'm not sure if I can do it that way either.
I have to admit UI design is a weak point of mine so any advice would be gratefully received.
EDIT: For future reference if anyone is looking for a similar answer, following Alan Moore's suggestion I have the following working exactly how I want it...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@drawable/bground"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.68"
android:background="@android:color/transparent"
/>
<Gallery
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.16"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.16"
android:background="@android:color/transparent"
/>
</LinearLayout>
I managed to find some other examples of using layout_weight
and decided to set the TextView
heights to 0dp
and also used floats for the weights. Working great. :)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…