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

Pra*_*u R 1 layout android

我正在编写一个Android应用程序,views其中3个一个在另一个之下.

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

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

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

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

bha*_*982 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"
    />
Run Code Online (Sandbox Code Playgroud)