2010-09-23 56 views

回答

1

請勿使用AbsoluteLayout。它被棄用,並且只是一個壞主意,因爲它在不同DPI的屏幕上看起來會不同。考慮使用RelativeLayout來代替。如果您可以提出更具體的問題,我們可以推薦一種替代解決方案。

請記住,你不應該實際使用這個,並且使用AbsoluteLayout已經間接地導致了癌症,並且還可能導致精神病,這裏是你如何做到這一點代碼假設你有一個AbsoluteLayout與一個孩子的EditText在XML佈局:

EditText editText = (EditText)findViewById(R.id.my_edit_text); 
AbsoluteLayout.LayoutParams abs_params = 
    new AbsoluteLayout.LayoutParams(
     //width in pixels, or AbsoluteLayout.FILL_PARENT/WRAP_CONTENT 
     60, 
     //height in pixels, or AbsoluteLayout.FILL_PARENT/WRAP_CONTENT 
     30, 
     //x position with regards to the origin 
     10, 
     //y position with regards to the origin 
     10 
    ); 
editText.setLayoutParams(abs_params); 

這裏有一些文檔頁面進行審查: http://developer.android.com/reference/android/widget/AbsoluteLayout.LayoutParams.html http://developer.android.com/reference/android/widget/AbsoluteLayout.html http://developer.android.com/reference/android/widget/EditText.html

我不承擔任何責任精神創傷馬y因使用AbsoluteLayout而發生。願上帝憐憫你的靈魂。 :)

+0

我想在java代碼中用它的x和y座標來定位它。我想知道如何做到這一點。感謝您的幫助。 – James 2010-09-24 15:22:13

+0

我已經爲你添加了一個例子。 – kcoppock 2010-09-24 16:25:05

+0

謝謝你的寶貴信息。你能否將上面的代碼轉換爲RelativeLayout.please ........ – James 2010-09-24 16:55:43