3
我使用adt插件在eclipse中製作測試應用程序。我想,當一個按鈕被點擊,將其移動在屏幕的隨機位置,我發現了一些例如周圍不受任何政府上網工程如何以絕對佈局以編程方式移動按鈕
Button noBtn = (Button) findViewById(R.id.NoBtn);
noBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
Button noBtn = (Button) findViewById(R.id.NoBtn);
AbsoluteLayout.LayoutParams OBJ=new
AbsoluteLayout.LayoutParams(35,35,408,160);
noBtn.setLayoutParams(OBJ);
}
});
,我通過使用機器人的layoutparam得到應用程序錯誤
那麼,什麼是錯誤? – Squonk 2012-02-04 21:33:44
我在xml中使用了RlativeLayout。所以我改變它'RelativeLayout.LayoutParams OBJ = newRelativeLayout.LayoutParams(50,80); OBJ.topMargin = randomHeight; int a = ApplicationUtils.getScreenHeight(getWindowManager()); int aa = ApplicationUtils.getScreenWidth(getWindowManager()); OBJ.leftMargin = randomWidth; noBtn.setLayoutParams(OBJ); – ddarellis 2012-02-05 09:38:25