在基于设备屏幕宽度/高度的布局中指定视图的相对维度

问题描述:

我正在编写一个具有3个views的Android应用程序。在基于设备屏幕宽度/高度的布局中指定视图的相对维度

每个视图必须具有相同的高度,具体取决于屏幕大小。

每个视图占据屏幕的整个宽度。

如何在layout xml中指定视图占用设备显示高度的三分之一高度?

这种情况下适合使用layout

尝试机器人:layout_weight = “1”

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 
<View 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:background="#F00" 
    /> 
<View 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:background="#0F0" 
    /> 
<View 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:background="#00F" 
    /> 

+0

这是如何指定高度,以平均分配? – Ram 2009-10-08 10:55:08

+0

从android文档:http://developer.android.com/guide/topics/ui/layout-objects.html在LinearLayout部分查找重量说明。 – Scott 2009-10-08 15:44:06

+1

为每个子视图指定android:layout_weight =“1”将直接指定布局来平均分配高度。请参阅Scott指出的文档。 – bhatt4982 2009-10-08 16:10:10