隐藏了大于屏幕边界的ImageView

时间:2013-11-07 13:17:20

标签: android android-imageview android-scrollview

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

1 个答案:

答案 0 :(得分: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;
}

希望这个帮助