1

我想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()。为什么?

谢谢你的回答!

4

0 回答 0