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

标签 android layout

我正在编写一个 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/

相关文章:

java - 录制的视频失真(FFMPEG)

java - 将 JComponents 与 JPanel 的左侧和右侧对齐

layout - flutter 中从右到左(RTL)

android - 错误:(191, 78)错误:在android中找不到符号变量ARGB_8888

android - View 寻呼机的页面转换工作异常

android - 在 frgamentActivity oncreate() 上检查 savedinstancestate 的原因

html - 如何将 div 与我的导航栏对齐?

xml - Android XML 布局指南

ios - UITableview 中各部分之间的空间

安卓。像 Telegram 一样滑动返回 Activity