我想知道在创建布局时是否可以使用百分比位置/大小。我想要的是这样的东西
^
|
|
| 68%
|
|
五、
画廊(高度相当于总屏幕尺寸的16%)
^
| 16%
五、
我在一个设备上进行测试,它在横向上有一个800×480实际像素的显示器,我现在用以下命令强制它
<;?xml version=“1.0”encoding=“utf-8”?>;
<;RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android"
android:layout\u width=“fill\u parent”
android:layout\u height=“fill\u parent”>;
<;陈列室
android:id=“@+id/gallery”
android:layout\u width=“fill\u parent”
android:layout_height=“80px”
android:layout_marginTop=“320px”
/&燃气轮机;
</相对寿命>;
显然,我不想硬编码固定的px单元,但我不能将68%或0.68用于layout\u marginTop(例如)。我已经看过了dp单位,但我也不确定我是否可以这样做
我必须承认,UI设计是我的一个弱点,所以我会感激地接受任何建议
编辑:如果有人在寻找类似的答案,根据艾伦·摩尔的建议,我将按照我想要的方式完成以下工作
<;?xml version=“1.0”encoding=“utf-8”?>;
<;LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android"
android:orientation=“垂直”
android:background=“@drawable/bground”
android:layout\u width=“fill\u parent”
android:layout\u height=“fill\u parent”>;
<;文本框
android:layout\u width=“fill\u parent”
android:layout\u height=“0dp”
android:layout_weight=“0.68”
android:background=“@android:color/transparent”
/&燃气轮机;
<;陈列室
android:id=“@+id/gallery”
android:layout\u width=“fill\u parent”
android:layout\u height=“包装内容”
android:layout_weight=“0.16”
/&燃气轮机;
<;文本框
android:layout\u width=“fill\u parent”
android:layout\u height=“0dp”
android:layout_weight=“0.16”
android:background=“@android:color/transparent”
/&燃气轮机;
</线性布局>;
我设法找到了一些使用layou weight的其他示例,并决定将TextView高度设置为0dp,并对权重使用浮动。工作很好。:)
我想你想要的是设置android:layout_weight
http://developer.android.com/resources/tutorials/views/hello-linearlayout.html
类似这样的内容(我只是将文本视图放在上面和下面作为占位符):
<;线性布局
android:orientation=“垂直”
android:layout\u width=“fill\u parent”
android:layout\u height=“fill\u parent”
android:weightSum=“1”>;
<;文本框
android:layout\u width=“fill\u parent”
android:layout\u height=“0dp”
android:layout_weight=“68”/>;
<;陈列室
android:id=“@+id/gallery”
android:layout\u width=“fill\u parent”
android:layout\u height=“0dp”
android:layout_weight=“16”
/&燃气轮机;
<;文本框
android:layout\u width=“fill\u parent”
android:layout\u height=“0dp”
android:layout_weight=“16”/>;
</线性布局>;