1
我正在編寫一個具有3個views
的Android應用程序。在基於設備屏幕寬度/高度的佈局中指定視圖的相對維度
每個視圖必須具有相同的高度,具體取決於屏幕大小。
每個視圖佔據屏幕的整個寬度。
如何在layout xml
中指定視圖佔用設備顯示高度的三分之一高度?
這種情況下適合使用layout
?
我正在編寫一個具有3個views
的Android應用程序。在基於設備屏幕寬度/高度的佈局中指定視圖的相對維度
每個視圖必須具有相同的高度,具體取決於屏幕大小。
每個視圖佔據屏幕的整個寬度。
如何在layout xml
中指定視圖佔用設備顯示高度的三分之一高度?
這種情況下適合使用layout
?
嘗試機器人: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"
/>
這是如何指定高度,以平均分配? – Ram 2009-10-08 10:55:08
從android文檔:http://developer.android.com/guide/topics/ui/layout-objects.html在LinearLayout部分查找重量說明。 – Scott 2009-10-08 15:44:06
爲每個子視圖指定android:layout_weight =「1」將直接指定佈局來平均分配高度。請參閱Scott指出的文檔。 – bhatt4982 2009-10-08 16:10:10