根据设备屏幕宽度/高度指定布局中视图的相对尺寸

时间:2009-10-08 09:10:17

标签: android layout

我正在编写一个Android应用程序,其中3 views一个低于另一个。

每个视图的高度必须相等,具体取决于屏幕尺寸。

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

如何在layout xml中指定视图必须占据设备显示高度的1/3高度?

在这种情况下使用适当的layout是什么?

1 个答案:

答案 0 :(得分:7)

尝试 android: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"
    />