how to auto scale a variable size ImageView?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

how to auto scale a variable size ImageView?

Postby reynolds » Wed Mar 18, 2009 8:54 am

Hi Guys,

Assuming I have a gallery, and each images in it, has varying dimensions. The ImagePreview (an ImageView object) which has the following config.

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <ImageView
  2.  
  3.         android:id="@+id/WallpaperPreview"
  4.  
  5.    android:layout_width="fill_parent"
  6.  
  7.    android:layout_height="wrap_content"
  8.  
  9.         android:layout_centerHorizontal="true"
  10.  
  11.         android:layout_centerVertical="true"
  12.  
  13.        
  14.  
  15.    />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


What I want is for this ImageView to auto resize its height, but the width is the maximum width of the screen, so the aspect ratio is correct. Problem is, currently the images stretches either from height or width.

Thanks in advance.
reynolds
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Mar 06, 2009 6:13 am
Location: Makati Philippines

Top

Postby reynolds » Wed Mar 18, 2009 9:47 am

somehow I was able to produce what I wanted...

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <ImageView
  2.  
  3.         android:id="@+id/WallpaperPreview"
  4.  
  5.    android:layout_width="fill_parent"
  6.  
  7.    android:layout_height="wrap_content"
  8.  
  9.         android:layout_centerHorizontal="true"
  10.  
  11.         android:layout_centerVertical="true"
  12.  
  13.         android:adjustViewBounds="true"
  14.  
  15.        
  16.  
  17.    />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


and the code must be
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.    
  2.  
  3.     ////////////////////////////////    
  4.  
  5.     public ImageView ImgPreview()
  6.  
  7.     {
  8.  
  9.         return (ImageView)findViewById(R.id.WallpaperPreview);
  10.  
  11.     }
  12.  
  13.     ////////////////////////////////
  14.  
  15.  
  16.  
  17. ////////////////////////////////
  18.  
  19. // position is the Id of a drawable in the IMG[] array
  20.  
  21.     public void displayPreview(final int position) {
  22.  
  23.        
  24.  
  25.         ImgPreview().setImageResource(IMG[position]);
  26.  
  27.         ImgPreview().setAdjustViewBounds(true);
  28.  
  29.  
  30.  
  31.     }
  32.  
  33.     ////////////////////////////////
  34.  
  35.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
reynolds
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Mar 06, 2009 6:13 am
Location: Makati Philippines

Postby p0lar » Tue May 12, 2009 2:05 pm

is there a way to do this scaling in a webview? so that the graphics displayed fit the window?
p0lar
Freshman
Freshman
 
Posts: 9
Joined: Thu Feb 05, 2009 12:07 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests