我正在尝试确定在创建布局时是否可以使用百分比位置/大小。我想要的是像这样的东西...
^
|
|
| 68%
|
|
v
Gallery (height equivalent of 16% total screen size)
^
| 16%
v
我正在测试一台设备,它在横向方向上拥有800x480个实际像素的显示屏,并且我目前正在使用以下方式进行强制...
<?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>
显然我不想硬编码固定的px
单位,但是我不能在layout_marginTop
(例如)中使用68%
或0.68
。 我查看了dp
单位,但我不确定是否可以用这种方式解决。
我必须承认UI设计是我的弱点,因此非常感谢任何建议。
编辑:对于将来寻找类似答案的人,请遵循Alan Moore的建议,我有以下解决方案完全符合我的要求...
<?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>
我找到了一些使用layout_weight
的其他示例,并决定将TextView
的高度设置为0dp
,并使用浮点数来设置权重。工作得很好。 :)