我在Eclipse中使用ADT插件创建了一个测试应用程序。当点击按钮时,我希望它在屏幕上随机移动位置。我在互联网上找到了一些示例,但都无法正常工作。
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);
}
});
我遇到了应用程序错误。
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