2010-09-23 59 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