Android:ImageView获得负宽度

时间:2013-08-25 16:02:46

标签: android

我不知道为什么,但是当我设置一个imageview(称为c)的宽度时,它会返回一个负值。 ivPiano也是一个imageView。

ViewTreeObserver vto = llPiano.getViewTreeObserver(); 
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 
        @Override 
        public void onGlobalLayout() { 
            llPiano.getViewTreeObserver().removeGlobalOnLayoutListener(this); 
            c.setTop(ivPiano.getTop());
            c.setLeft(ivPiano.getLeft());
            ShowMessageLong(ivPiano.getWidth());
            c.getLayoutParams().width = ivPiano.getWidth();
            c.getLayoutParams().height= ivPiano.getHeight();
            c.bringToFront();
            ShowMessageLong(c.getWidth());
        } 
    });

ShowMessageLong()只是创建并显示祝酒词。第一次(ivPiano的宽度)显示1200,然后第二次(c的宽度)返回-22。有什么想法吗?在此先感谢!!

0 个答案:

没有答案