Anna Gotkevish
Anna Gotkevish

Reputation: 57

Increase image beyond the screen size

I want to display an image on the screen but the image edges will be larger than the size of the screen itself. IE if the maximum screen width is X then I want the width of the image will be X +100 and maximum screen height is Y then the image height is Y +100.

I want this option for the ability to move the image to the right / left and still the image will be shown on the whole screen.

Upvotes: 0

Views: 988

Answers (1)

m039
m039

Reputation: 1339

For this purpose I use RelativeLayout with requestLayout function:

<?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> 

And in the code generate an appropriate image:

    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();

Upvotes: 2

Related Questions