本章節翻譯自《Beginning-Android-4-Application-Development》,如有翻譯不當的地方,敬請指出。
原書購買地址 http://www.amazon.com/Beginning-Android-4-Application-Development/dp/1118199545/
使用AbsoluteLayout,可以指定它其中的子View的確切位置。觀察如下main.xml中的代碼:
- <? xml version = "1.0" encoding = "utf-8" ?>
- < AbsoluteLayout xmlns:android = "http://schemas.android.com/apk/res/android"
- android:layout_width = "fill_parent"
- android:layout_height = "fill_parent" >
- < Button
- android:layout_width = "188dp"
- android:layout_height = "wrap_content"
- android:layout_x = "126px"
- android:layout_y = "361px"
- android:text = "Button" />
- < Button
- android:layout_width = "113dp"
- android:layout_height = "wrap_content"
- android:layout_x = "12px"
- android:layout_y = "361px"
- android:text = "Button" />
- </ AbsoluteLayout >
但當activity被繪制在一個高分辨率的屏幕上時,AbsoluteLayout就會出現某些問題。
下圖是,在使用同樣代碼的前提下,高分辨率屏幕上顯示出來的效果。
出于這個原因,從Android1.5開始,Google官方已經不推薦使用這個布局了,盡管它現在還是可以使用的。在創建UI的時候,應該避免使用AbsoluteLayout這個布局,因為,Android并不確保會在將來的版本中還繼續支持它。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
