簡體   English   中英

根據設備屏幕的寬度/高度指定布局中視圖的相對尺寸

[英]Specifying the relative dimension of views in a layout based on device screen width/height

我正在編寫一個具有3個views的Android應用程序,一個在另一個views之下。

每個視圖的高度必須相等,具體取決於屏幕尺寸。

每個視圖占據屏幕的整個寬度。

如何在layout xml中指定視圖必須占據設備顯示高度的1/3高度?

在這種情況下將使用什么合適的layout

嘗試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"
    />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM