Scroll A Big Image in ImageSwitcher

Put your problem here if it does not fit any of the other categories.

Scroll A Big Image in ImageSwitcher

Postby nico » Thu Jan 10, 2008 6:50 am

Hi, all

need help, again :wink: I tried to view a big image in its real size (not fit to screen) using ImageSwitcher. I set the ScaleType of ImageView to ScaleType.CENTER. It worked but i cant scroll the image, how can i do it?I tried setHorizontalScrollBarEnabled and setVerticalScrollBarEnabled but still not working :( :?

This is the source:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.nico.imageSwitcherTest;
  2.  
  3.  
  4.  
  5. import java.net.URISyntaxException;
  6.  
  7.  
  8.  
  9. import com.nico.imageSwitcherTest.R;
  10.  
  11.  
  12.  
  13. import android.app.Activity;
  14.  
  15. import android.net.ContentURI;
  16.  
  17. import android.os.Bundle;
  18.  
  19. import android.view.View;
  20.  
  21. import android.view.ViewGroup.LayoutParams;
  22.  
  23. import android.widget.ImageSwitcher;
  24.  
  25. import android.widget.ImageView;
  26.  
  27. import android.widget.ViewSwitcher;
  28.  
  29. import android.widget.ImageView.ScaleType;
  30.  
  31.  
  32.  
  33. public class ImageSwitcherTest extends Activity implements ViewSwitcher.ViewFactory {
  34.  
  35.     private ImageSwitcher mSwitcher;
  36.  
  37.  
  38.  
  39.         /** Called when the activity is first created. */
  40.  
  41.     @Override
  42.  
  43.     public void onCreate(Bundle icicle) {
  44.  
  45.         super.onCreate(icicle);
  46.  
  47.         setContentView(R.layout.main);
  48.  
  49.        
  50.  
  51.         mSwitcher = (ImageSwitcher) findViewById(R.id.switcher);
  52.  
  53.                 mSwitcher.setFactory(this);
  54.  
  55.                
  56.  
  57.                 try {
  58.  
  59.                         mSwitcher.setImageURI(new ContentURI("/tmp/somebigsizepicture.png"));
  60.  
  61.                 } catch (URISyntaxException e) {
  62.  
  63.                         // TODO Auto-generated catch block
  64.  
  65.                         e.printStackTrace();
  66.  
  67.                 }
  68.  
  69.     }
  70.  
  71.    
  72.  
  73.     public View makeView() {
  74.  
  75.                 // TODO Auto-generated method stub
  76.  
  77.                 ImageView i = new ImageView(this);
  78.  
  79.                 i.setBackgroundColor(0xFF000000);
  80.  
  81.                 i.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
  82.  
  83.                                 LayoutParams.FILL_PARENT));
  84.  
  85.                 i.setScaleType(ScaleType.CENTER);
  86.  
  87.                 return i;
  88.  
  89.         }
  90.  
  91. }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


And here is the screenshot: (i want to be able to scroll or pan the image so i can see the rest of image) :?
Attachments
device.png
device.png (7.12 KiB) Viewed 13408 times
nico
Junior Developer
Junior Developer
 
Posts: 19
Joined: Tue Nov 27, 2007 10:33 am
Location: Indonesia

Top

Postby snowtiger » Thu Jan 10, 2008 11:30 am

One possible solution could be the following:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. @Override
  3.  
  4.     public boolean onKeyUp(int keyCode, KeyEvent event) {
  5.  
  6.         try {
  7.  
  8.             switch (keyCode) {
  9.  
  10.             case KeyEvent.KEYCODE_DPAD_UP:
  11.  
  12.                 yourView.scrollBy(0, 10);
  13.  
  14.                 break;
  15.  
  16.             case KeyEvent.KEYCODE_DPAD_LEFT:
  17.  
  18.                 yourView.scrollBy(10, 0);
  19.  
  20.                 break;
  21.  
  22.             case KeyEvent.KEYCODE_DPAD_RIGHT:
  23.  
  24.                 yourView.scrollBy(-10, 0);
  25.  
  26.                 break;
  27.  
  28.             case KeyEvent.KEYCODE_DPAD_DOWN:
  29.  
  30.                 yourView.scrollBy(0, -10); //dunno if all directions are correct <img src="http://www.anddev.org/images/smilies/smile.png" alt=":)" title="Smile" />
  31.  
  32.                 break;
  33.  
  34.             }
  35.  
  36.         } catch (DeadObjectException e) {
  37.  
  38.            Log.e(getString(R.string.app_name), e.getMessage());
  39.  
  40.         }
  41.  
  42.         return super.onKeyUp(keyCode, event);
  43.  
  44.     }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


With the keypad u can scroll 10 pixels in every direction. Of course u can add some checking funktion, if the border is already reached, before scrolling towards it.
snowtiger
Developer
Developer
 
Posts: 34
Joined: Fri Dec 21, 2007 10:44 am

Postby nico » Thu Jan 10, 2008 1:58 pm

Hi snowtiger,

the directions all wrong :D but it works, thx a lot :wink: Though there's something weird with ScaleType.CENTER, the image is cropped on the up and left border :( So when i scrolled it using your suggestion, it can reach the right and bottom border but not the up and left border. what's goin on here?

Actually i'm trying to zoom in and out the image viewed on ImageSwitcher. Any other suggestion to accomplish this?Thanksss..
Attachments
rightBorder.png
This is when i used ScaleType.CENTER then scroll all the way to right border
rightBorder.png (7.84 KiB) Viewed 13381 times
fitScale.png
This is when i didnt use ScaleType.CENTER
fitScale.png (7.27 KiB) Viewed 13381 times
nico
Junior Developer
Junior Developer
 
Posts: 19
Joined: Tue Nov 27, 2007 10:33 am
Location: Indonesia

Postby nico » Fri Jan 11, 2008 5:01 am

still can't figure out the croped-border-when-using-StyleType.CENTER-problem, anyone knows how to solve it? but i found another solution for image gallery that can zoom in and out, i just used the WebView instead of ImageView 8)
nico
Junior Developer
Junior Developer
 
Posts: 19
Joined: Tue Nov 27, 2007 10:33 am
Location: Indonesia

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 15 guests