【问题标题】:Increase image beyond the screen size将图像放大到超出屏幕尺寸
【发布时间】:2011-10-30 20:50:37
【问题描述】:

我想在屏幕上显示图像,但图像边缘会大于屏幕本身的尺寸。 IE 如果最大屏幕宽度为 X 则我希望图像的宽度为 X +100,最大屏幕高度为 Y 则图像高度为 Y +100。

我希望该选项能够将图像向右/向左移动,并且图像仍将显示在整个屏幕上。

【问题讨论】:

    标签: android imageview


    【解决方案1】:

    为此,我使用RelativeLayoutrequestLayout 函数:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 
        xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_height="match_parent" 
        android:layout_width="match_parent">
    
      <ImageView
          android:id="@+id/iv"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerInParent="true"/>
    
    </RelativeLayout> 
    

    并在代码中生成合适的图片:

        Display display = getWindowManager().getDefaultDisplay(); 
        int     width   = display.getWidth();
        int     height  = display.getHeight();
    
        // example code with bigger dimensions than the screen
    
        Bitmap b =  Bitmap.createBitmap(width + 100, height + 100, Bitmap.Config.ARGB_8888);
    
        // draw smth on the bitmap
    
        Canvas c = new Canvas(b);
        Paint  p = new Paint();
    
        p.setColor(Color.RED);
    
        c.drawCircle(b.getWidth() / 2,
                     b.getHeight() / 2,
                     Math.min(b.getWidth(), b.getHeight()) / 2, 
                     p);
    
        // set the image
        ImageView iv = (ImageView) findViewById(R.id.iv);
        iv.setImageBitmap(b);
    
        // call this method to change imageview size
        iv.requestLayout();
    

    【讨论】:

    • 如果我想画圆,这很好,但我想画一个现有的可绘制图像。我怎样才能做到这一点?谢谢。
    • 很抱歉,我不知道现有的类可以为您做什么,也许是带有滚动视图的东西。但是如果你想要比屏幕更大的图像,我给了你解决方案。如果您想从资源中设置现有图像(为简单起见),您可以使用d = getResource().getDrawable(R.drawable.image)iv.setImageDrawable(d)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-28
    相关资源
    最近更新 更多