0

我有imageview一个scrollview. 但是,在旋转时,横向图像的高度大于屏幕。这会导致imageview消失。这不是内存问题,因为我已经删除了图像本身的设置,只是设置了背景颜色。如果我设置一个较小的高度,图像视图不会消失。当它的高度大于屏幕时,有什么方法可以防止图像视图消失?

4

1 回答 1

0

我认为你需要使用Display类这是它的完整示例

    //get Display info
    Display d = getWindowManager().getDefaultDisplay(); 
    //get screen h/w
    int w = d.getWidth();  
    int h = d.getHeight(); 

    ImageView img = ( ImageView ) findViewById(R.id.myimage);

    //i want to set imageview full screen for example
    img.getLayoutParams().height = h; 
    img.getLayoutParams().width  = w;

    // and this to set h or w by percentage let say 15% of screen 
    img.getLayoutParams().height = (int)(h/100)*15; 
    img.getLayoutParams().width  = (int)(w/100)*15; 

//or if height large than screen resize it
if ( img.getHeight() > h)
{
  img.getLayoutParams().height = (int)(h/100)*95;
}

希望这有帮助

于 2013-11-07T13:27:53.713 回答