点击ImageButton
后,我想更改ImageButton
位置。我使用该代码,但它不起作用。代码:
imb.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
LayoutParams ibPar = (LayoutParams) imb.getLayoutParams();
Random randomIntGenerator = new Random();
int randomLocationX = randomIntGenerator.nextInt(100);
int randomLocationY = randomIntGenerator.nextInt(400);
ibPar.x = randomLocationX;
ibPar.y = randomLocationY;
imb.setLayoutParams(ibPar); }
});
LayoutParams ibPar = (LayoutParams) imb.getLayoutParams()
出错。为什么呢?
感谢您的回答!