2013-04-24 84 views
0

我創建了一個應該隨機放幾個按鈕(或imageview)的應用程序,我傳遞最大值和最小值,並從那裏取座標。在2.3.3中放置座標按鈕android

問題是,在4.2.2編譯是完美的,但我尋求爲2.3.3工作,因爲我想分享我的應用程序在谷歌播放。

我使用的是android 4.2.2。做應用程序。

button.setX()和button.setY()

但在安卓2.3.3(API級別10)可以使用的方法

你知道我怎麼會在API級別10?

非常感謝!

+0

如果你得到任何錯誤,只是貼上logcat的這裏在你的問題 – umesh 2013-04-24 08:51:58

+0

我沒有錯誤什麼的,只有當我從4.2.2更改爲2.3.3 eclipse sais不能使用「button.setX」或「button.SetY()」 – CristianCV 2013-04-24 09:17:35

+0

這意味着這些方法不可用API級別10,意味着爲Android 2.3.3 – umesh 2013-04-24 09:19:31

回答

2

你應該看看這個答案:

https://stackoverflow.com/a/12195999/2140191

//The WRAP_CONTENT parameters can be replaced by an absolute width and height or the FILL_PARENT option) 
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); 
params.leftMargin = 50; //Your X coordinate 
params.topMargin = 60; //Your Y coordinate 

之後的的LayoutParams添加到使用按鈕:

button.setLayoutParams(params); 
0

嘗試使用

setTranslationX(float xVal) 

公共浮動的getX()

在API級別11 這種觀點的視覺x位置,以像素爲單位。這相當於translationX屬性加上當前的左側屬性。

返回 此視圖的視覺x位置,以像素爲單位。

+0

我想要在API級別10中執行此操作,api級別11是針對android 3.0的,而大多數android設備都具有三個較小的版本 – CristianCV 2013-04-24 09:36:27