我正在编写一个 android 应用程序,它有 3 个 views
一个在另一个下面。
每个 View 必须具有相同的高度,具体取决于屏幕大小。
每个 View 占据屏幕的整个宽度。
如何在 layout xml
中指定 View 必须占据设备显示高度的 1/3 高度?
在这种情况下使用什么合适的布局
?
最佳答案
尝试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"
/>
关于android - 根据设备屏幕宽度/高度指定布局中 View 的相对尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1536601/