我正在编写一个Android应用程序,其中3 views
一个低于另一个。
每个视图的高度必须相等,具体取决于屏幕尺寸。
每个视图占据屏幕的整个宽度。
如何在layout xml
中指定视图必须占据设备显示高度的1/3高度?
在这种情况下使用适当的layout
是什么?
答案 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"
/>