如何更改Imagebutton位置?

时间:2013-04-02 19:39:59

标签: android imagebutton

点击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()出错。为什么呢?

感谢您的回答!

0 个答案:

没有答案
相关问题