例如 AbsoluteLayout, 這個排版方式可以在屬性標籤裡, 設定元件在畫面上的 x,y 位置,
依照像素關係設定, 在 1.5 後 AbsoluteLayout 被 Google 認為 deprecated(聲明不贊成)
原因在於 Android 有越來越多手持設備, 目的實際螢幕像素不同, 所以直接定座標可能會出現排版問題. 在 1.5 後, 我們要使用的是其它的排版方式來解決.(Google 建議的是 FrameLayout 或是 RelativeLayout)
下面的例子是使用 RelativeLayout 插入一個 Button 元件的做法 :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/CheckButton"
android:text="GUESS !"
android:textSize="20px"
android:textStyle="bold"
android:layout_width="132px"
android:layout_height="wrap_content"
android:layout_marginLeft="100px"
android:layout_marginTop="384px"
/>
裡面的關鍵 layout_marginLeft 表示從 marginGravity 的錨點算過來的位置, 元件左方的邊界(Margin), 那麼就是對應到以前的 layout_x; 而 layout_marginTop 就是對應了以前的 layout_y只要替換這部份,應該就能成功的排好版. 不過我發現1.0/1.1 時, 不需訂 layout_width 或 layout_height 也能過關, 1.5 裡不行, 是否新版裡對排版要求嚴謹些了呢 ?
沒有留言:
張貼留言