본문 바로가기
프로그래밍 놀이터/안드로이드, Java

[Android/안드로이드] Gallery ( 갤러리 ) sample code.

by 돼지왕 왕돼지 2012. 2. 28.
반응형


Sample Code


<Layout>
<Gallery xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@+id/gallery"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:spacing="5px"
       android:animationDuration="1500"/>
 
<Java>
Gallery g = (Gallery) findViewById(R.id.gallery);
g.setAdapter(new ImageAdapter2(this));
 
class ImageAdapter2 extends BaseAdapter{
   private Context con;
   private int[] imageIds = { ~, ~, ~, ~, ~};
 
   public ImageAdapter2(Context c){con = c; }
   public int getCount(){ return mImageIds.length; }
   public Object getItem(int position){ return imageId[position]; }
   public long getItemId(int position) { return position; }
 
   public View getView(int position, View convertView, ViewGroup parent){
      ImageView imageView;
      if (convertView == null){
         imageView = new ImageView(con);
      }
      else{
         imageView = (ImageView)convertView;
      }
     
      imageView.setImageResources(imageId[position]);
      imageView.setScaleType(ImageView.ScaleType.FIT_XY);
      imageView.setLayoutParams(new Gallery.LayoutParams(136, 88));
 
      return imageView;
   }
} 



로그인 없이 추천 가능합니다. 손가락 꾸욱~

반응형

댓글