ImageView ... hoe to set imahe size

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

ImageView ... hoe to set imahe size

Postby Mr.Xprt » Sun May 03, 2009 9:34 pm

Hi

am using GridView to display my images by ImageView the Question is how to set size of images

or that imposible

that is my adapter

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package Project.yahia;
  2.  
  3. import android.content.Context;
  4. import android.view.View;
  5. import android.view.ViewGroup;
  6. import android.widget.BaseAdapter;
  7. import android.widget.GridView;
  8. import android.widget.ImageView;
  9.  
  10. public class MyImageAdapter extends BaseAdapter{
  11. private Context mContext;
  12.         public MyImageAdapter(Context c){
  13.                 mContext =c;
  14.                
  15.         }
  16.         @Override
  17.         public int getCount() {
  18.                
  19.                  return mThumbIds.length;
  20.  
  21.         }
  22.  
  23.         @Override
  24.         public Object getItem(int position) {
  25.                 // TODO Auto-generated method stub
  26.                 return null;
  27.         }
  28.  
  29.         @Override
  30.         public long getItemId(int position) {
  31.                 // TODO Auto-generated method stub
  32.                 return 0;
  33.         }
  34.  
  35.         @Override
  36.         public View getView(int position, View convertView, ViewGroup parent) {
  37.                 ImageView imageView ;
  38.                
  39.                 if(convertView ==null){
  40.                     imageView = new ImageView(mContext);
  41.                     imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
  42.                     imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
  43.                     imageView.setPadding(8, 8, 8, <img src="http://www.anddev.org/images/smilies/cool.png" alt="8)" title="Cool" />;
  44.                 } else {
  45.                     imageView = (ImageView) convertView;
  46.                 }
  47.  
  48.                 imageView.setImageResource(mThumbIds[position]);
  49.                 return imageView;
  50.             }
  51.        
  52.     private Integer[] mThumbIds = {
  53.             R.drawable.shutdown2,R.drawable.android
  54.             ,R.drawable.hibernat,R.drawable.suspend,R.drawable.sudo};
  55. }
  56.  
  57.             // references to our images
  58.  
  59.  
  60.                
  61.        
  62.  
  63.  
  64.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


and my XML


Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:orientation="vertical"
  4.    android:layout_width="fill_parent"
  5.    android:layout_height="fill_parent"
  6.         android:background="@drawable/android3">
  7.  
  8.        
  9.      
  10.      <GridView xmlns:android="http://schemas.android.com/apk/res/android"
  11.    android:id="@+id/gridview"
  12.    android:layout_width="wrap_content"
  13.    android:layout_height="wrap_content"
  14.    android:numColumns="2"
  15.    android:verticalSpacing="10dp"
  16.    android:horizontalSpacing="10dp"
  17.    android:columnWidth="150dp"
  18.    android:stretchMode="columnWidth"
  19.    android:gravity="center"
  20.    android:scaleType="fitStart"
  21.    />
  22.    
  23.         </LinearLayout>
  24.  
  25.  
  26.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


this is my out put

Image


see android iamge it's 500x500 px and the others are 100x100

how can i control the size of image
Mr.Xprt
Freshman
Freshman
 
Posts: 7
Joined: Wed Apr 22, 2009 9:13 pm
Location: Egypt

Top

Reply

Postby satishkumar_lskin » Mon May 04, 2009 12:02 pm

Hi,
In ur Adapter class, in the method getView() , instead of this line

imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

can u use ,

imageView.setScaleType(ImageView.ScaleType.FIT_XY); ?

Is this change helpful ?
satishkumar_lskin
Developer
Developer
 
Posts: 32
Joined: Mon Oct 20, 2008 8:15 am
Location: Coimbatore , TamilNadu, India

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 8 guests