0

I have a 1500x1500px image and i set it as android:background and set layout width and height as 1500px in FrameLayout. I want to see the whole image but I can only see a part of it because I cannot swipe to see the whole. I set the image as background so I can put buttons on the image.

How to view a background image beyond the phone's screen size?

MainActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Bitmap bmp = BitmapFactory.decodeResource(this.getResources(),
            R.drawable.finalmap);
    ImageView imageView = new ScrollableImageView(this);// or find it by id
    android.view.ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
    layoutParams.width = bmp.getWidth();
    layoutParams.height = bmp.getHeight();
    imageView.setLayoutParams(layoutParams);
}
ThisGuy
  • 833
  • 1
  • 9
  • 19

2 Answers2

1

Use ScrollableImageView (https://github.com/Egorand/android-scrollable-imageview/blob/master/src/com/egorand/scrollableimageview/ScrollableImageView.java) for implementing scrolling of ImageView.

Example: (Remove all LayoutParam import and then add this)

import android.view.ViewGroup.LayoutParams;

Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.your_1500x1500px_image); private ImageView imageView = new ScrollableImageView(this);// or find it by id imageView.setLayoutParams(new LayoutParams(bmp.getWidth(), bmp.getHeight())); imageView.setImageBitmap(bmp);

Don't forget to copy ScrollableImageView class in your package !!!!

try like this

android.view.ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
layoutParams.width = bmp.getWidth();
layoutParams.height = bmp.getHeight();
imageView.setLayoutParams(layoutParams);
Vishal Makasana
  • 960
  • 2
  • 7
  • 15
  • thanks. I have read a lot of git repos that I can put in my android project but the problem is that I cannot add it to the android. I have tried procedures on how to add a library in android studio like this one: http://stackoverflow.com/questions/16588064/how-do-i-add-a-library-project-to-the-android-studio. Can you help me how I can add/import a library like the class above in android studio. – ThisGuy Mar 21 '15 at 11:55
  • For this problem, you have to just copy this java file to your package. and then use it. – Vishal Makasana Mar 21 '15 at 13:26
  • ok. Btw, the `new LayoutParams` and `context` is in red line, I guess it does not read them. What would I do with it? – ThisGuy Mar 21 '15 at 13:29
  • try Optimizing imports CTRL + ALT + O. and tell me what happens . – Vishal Makasana Mar 21 '15 at 13:33
  • i optimized mainactivity.java but still both are in red line. it seems there is no library that reads them. – ThisGuy Mar 21 '15 at 13:35
  • please if you don't mind post your main activity code so that i can get idea whtat's wrong – Vishal Makasana Mar 21 '15 at 13:41
  • im using framelayout and i changed `LayoutParams` to `FrameLayout.LayoutParams`. How about the `context`? – ThisGuy Mar 21 '15 at 13:41
  • i have updated my post, u can see my mainactivity now. – ThisGuy Mar 21 '15 at 13:43
  • now it just says `Unfortunately, App has stopped`. I have updated my post above, kindly take a look. – ThisGuy Mar 21 '15 at 14:03
  • So until now, I haven't made it run. I don't know what is wrong and its hard for a newbie like me. – ThisGuy Mar 22 '15 at 06:48
0

well i don't know if it's possible with background or not but you can achieve this by putting an imageview inside frame layout or relative layout with both width and height match parent scaleType set to fitXY.

Alireza Ahmadi
  • 5,122
  • 7
  • 40
  • 67
  • Thanks but that would make the image smaller(not in size but when you view it). I don't want to set `match_parent`. I want to swipe over the image in 1500x1500 width and height. – ThisGuy Mar 21 '15 at 11:41